This is more of a suggestion rather than an issue.
This is how I am defining my custom decorators so I can use them in my unit tests:
@inject
def http_get_performance_test(url: str,
threads=10,
duration=60,
html_reporter=Provide[Container.html_report]): # injected from dependency injection for a unified report
def decorator(fun):
def wrapper(*args, **kwargs):
timer = UniformRandomTimer(1000, 2000)
http_sampler = HttpSampler(
fun.__name__,
url,
timer
)
tg = ThreadGroupWithRampUpAndHold(
threads, 1, duration, http_sampler, name="Some Name"
)
tp = TestPlan(tg, html_reporter)
fun(*args, **kwargs, test_plan=tp)
return wrapper
return decorator
When in use the unit tests look a lot cleaner:
class TestTestPlanClass(TestCase):
@e2e.utils.decorators.http_get_performance_test(
url="https://postman-echo.com/get?var=${__Random(0,10)}",
threads=10,
duration=30
)
def test_2(self, test_plan):
stats = test_plan.run()
self.assertLess(stats.sample_time_99_percentile_milliseconds, 2000)
I believe you can achieve a much nicer Developer Experience with decorators (you can also chain them)
This is more of a suggestion rather than an issue.
This is how I am defining my custom decorators so I can use them in my unit tests:
When in use the unit tests look a lot cleaner:
I believe you can achieve a much nicer Developer Experience with decorators (you can also chain them)