Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to call on_start before each testcase, like setup in unittest? #781

Closed
ityoung opened this issue Apr 23, 2018 · 8 comments
Closed

How to call on_start before each testcase, like setup in unittest? #781

ityoung opened this issue Apr 23, 2018 · 8 comments

Comments

@ityoung
Copy link

ityoung commented Apr 23, 2018

Feature request

Setup method like unittest

Expected behavior

Method on_start only run once, but my testcase require different parameter recieved from an HTTP response.

If I get this variable with on_start, then only first test can pass; and if I call the get_parameter method in testcase, it will makes testresult inaccurate for the time waiting for response.

Actual behavior

Is there any method like setup with unittest(I didn't find in document), or any suggests that can solve this scene?

@cgoldberg
Copy link
Member

similar feature is already implemented and the code has landed in master.
see:
https://docs.locust.io/en/latest/writing-a-locustfile.html#setups-teardowns-on-start-and-on-stop

@ityoung
Copy link
Author

ityoung commented Apr 23, 2018

@cgoldberg many thanks, and sorry for I didn't see that.

@ityoung
Copy link
Author

ityoung commented Apr 26, 2018

@cgoldberg hi, I find out that the on_start method will not run after times executing testset great than Number of users to simulate I input on webpage, is that a bug? I want to run on_start every time, and I have to set the locust_count a very large number...

@cgoldberg
Copy link
Member

@ityoung, I'm sorry, but I don't understand your issue description or what you are asking. Can you clarify?

@ityoung
Copy link
Author

ityoung commented Apr 27, 2018

@cgoldberg sorry for my poor english..

What I want:

For a taskset class, method on_start can run each time before tasks be executed, not matter how many user I simulate(input on webUI).

What I get:

When I type 10 in Number of users to simulate text field, the on_start will run 10 times, but the test is going on, and on_start will not be called ever since, and that make my tasks uninitialized.

Question:

Is locust set on_start running times as number of users to simulate on purpose?

@maingoh
Copy link

maingoh commented Mar 4, 2022

I am also looking for a on_start/setup and on_stop/teardown hook at the taskset level, not the user level.

I would like to create/cleanup a resource before/after each taskset, and I don't want this resource to be reused. If I use on_start or test_start hook, it will only fire when the user is created, not when the taskset is launched.

Or I would need a way for locust to recreate a user each time to simulate independant users when using with LoadTestShape.

@dagosi
Copy link

dagosi commented Jul 6, 2022

I'm not sure why this issue is closed, but I'm looking for the same thing. I need to create a resource in the server's DB before making a request, and this needs to happen before each request (or task). I haven't found a hook that works this way. Any suggestions?

@cyberw
Copy link
Collaborator

cyberw commented Jul 6, 2022

There’s no built in way to do that, but you can override the run task method, as done here for example https://github.com/SvenskaSpel/locust-plugins/blob/bf4097eb3a04580de886b5b138151a6b0d21660e/locust_plugins/__init__.py#L209

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants