-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Teardown for parametrized module scope fixtures is not executed in the teardown phase #3032
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
Comments
GitMate.io thinks the contributors most likely able to help are @nicoddemus, and @RonnyPfannschmidt. |
Hi @samjl, really sorry about the delay.
(comments added by me) Your reasoning makes sense, but that's how pytest works currently: at the point that a fixture is requested is the point where pytest decides if the previous fixture instance must be teardown and a new one created. This is done at this point: Lines 771 to 794 in 794fb19
In line This is the current design and unfortunately I don't think it is easy to change; it would probably require a rewrite of the fixture code to be more proactive (look at the current items and decide which fixtures to create and destroy) rather than reactive (try to create fixtures and decide to teardown previous ones based on the ones being created). I hope the explanation makes sense. Unless I'm mistaken I think we will have to close this as is because it will require a major rewrite as I explained above. 😕 @RonnyPfannschmidt any comments? |
That makes sense and I agree it sounds like a lot of effort for not much gain... I will try to find some time today to add the documentation and some example tests so you can get an idea of how it works. What I have so far is located here samjl/pytest-phases. I have no issues with closing this issue. |
Cool @samjl thanks for understanding. I look forward to take a look at your plugin. Unrelated question: do you use the |
@nicoddemus Yes, I use the |
Cool, thanks for the answer. |
I am writing a plugin to track saved results during the different test phases (setup, call, teardown) and use the pytest_runtest_setup, pytest_pyfunc_call, pytest_runtest_teardown functions to track the current test phase.
However, I have encountered a problem tracking the test phase when parametrizing module scoped fixtures.
The intermediate module teardown (all but the last module fixture parameter teardown) is executed after both pytest_runtest_teardown and pytest_report_teststatus (for the teardown phase) have executed but it would be expected to execute when the pytest_runtest_teardown yields. This is shown in the annotated output below.
The test module and conftest files required to reproduce the issue are also included.
Note that:
test script:
conftest:
pytest_teardown.zip
The text was updated successfully, but these errors were encountered: