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

Feature request: on_quit() #248

Closed
kalantar opened this issue Feb 27, 2015 · 8 comments
Closed

Feature request: on_quit() #248

kalantar opened this issue Feb 27, 2015 · 8 comments

Comments

@kalantar
Copy link

There is a way to define a method that executes when a task set starts; ie, on_start(). It would be useful to have a similar method, on_quit() when the task set is terminated.

I want my task set to share a common identifier. I create this in on_start(). A side effect of the tests is to create an artifact with this identifier in the name. When the tests terminate, I want the artifact to be deleted.

I've tried using the events.on_quitting event for this. However, as far as I can tell, this is called in the context of the Locust object, not in the context of the task itself.

@jakubgs
Copy link

jakubgs commented Apr 10, 2015

+1

I don't get why on_quit() was not there from the start. It seems like such an obviously necessary functionality.

@DataGreed
Copy link

Well, that would be a great feature, something like a cleanup for automated tests.

In my case there are a lot of test users registering and creating some content, it would be nice to have a way to automatically remove all of this when the test are done (though, in real life I would rather do it myself, so I can inspect the data in case if something goes wrong during the tests)

@vitawasalreadytaken
Copy link

+1, the equivalent of tearDown is needed to remove data created during the load test.

I'm using this simple workaround at the moment. Since on_quit is a bound method, it still has the task set's context when it's executed.

class MyTaskSet(TaskSet):
    def on_start(self):
        locust.events.quitting += self.on_quit

    def on_quit(self):
        ...

@jurisbu
Copy link

jurisbu commented Feb 23, 2016

+1

@onurg
Copy link

onurg commented Feb 24, 2016

+1 this is a must have if engs need to continue working with this framework.

@mclate
Copy link

mclate commented Jul 20, 2017

Also would opt in for this one. Solution suggested by @ze-phyr-us works good if you have plain structure (With only one task_set), but doesn't really work with nested tasksets as they won't execute their teardown up until whole locust process quits.

So that's definitely a must have here.

@tazle
Copy link

tazle commented Nov 16, 2018

How is on_quit() different from on_stop()?

@cgoldberg
Copy link
Member

this is an old request that has already been implemented: https://docs.locust.io/en/stable/writing-a-locustfile.html#setups-teardowns-on-start-and-on-stop

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

10 participants