-
Notifications
You must be signed in to change notification settings - Fork 72
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
Ensure cleanup always runs by utilizing a pytest finalizer. #33
base: master
Are you sure you want to change the base?
Conversation
Hi @not-josh ! Thanks for contributing :-) I'm a bit surprised by this change. According to the Pytest fixtures documentation, it doesn't seem like exceptions are propagated like this. See Fixture finalization / executing teardown code. |
Pytest won't run a fixture's teardown if the initial setup fails for any reason. A try/finally block will still pass the exception upward while ensuring it's teardown code is still ran. Alternatively (and likely cleaner), this can also be done utilizing the addfinalizer function of the pytest fixture subrequest. In the example below, I've added the request as a parameter, moved the teardown code into it's own function, and added that function the request using addfinalizer. What do you think? Edit: I've updated my changes to reflect the code snippet below.*
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, the approach with the finalizer is safer, yes, but I've played a bit with docker-compose, and I have a reservation about this maybe not working. Annoyingly, for some reason I can't actually test your code right now (can't pull the images on a project that that would be a good test...).
So the problem I have is that running down
alongise up
might not have reliable results and leave some stuff behind. So the post important thing is that Python always kills the up process if it's still running. Will that happen if you throw an exception after execute docker_compose.execute('up --build -d')
? Or give it a few seconds with sleep and then throw it? Are to containers getting nicely cleaned out? I wanted to test it with a bigger project that I have, but I'm having weird issues right now, like I said.
With that said - if ctrl+c will kill the compose up process with will make down always clean up everything, then this looks good to me.
Hello @butla! Raising an exception during or after Part of this is because As for Running |
Also, I've fixed the pep8 errors with the tests, however they're still broken due to unrelated changes. :( |
@not-josh I see the breakages. Got a solution for that but it raises another question - I'll link the issue/PR. As for this PR in itself - I'll try to come up with code to illustrate the problem I described, maybe I'll have the time in the next two days. |
Issue, leading to the code fix and some thoughts - #35 |
Is this still valid, please? |
Trying to kill pytest with SIGINT (CTRL+C) causes docker, or it's network bridges, to stay alive. I discovered this when one of the surviving network bridges killed my internet connection entirely. At other times, my computer's performance will drop from leftover docker containers running. Life is hard for the impatient!
While this will not keep someone mashing ctrl+c safe, I've found this small change reduces the possibility of leftover waste without a noticeable performance cost.