-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Call cleanup functions if explicit teardown is needed #7049
Conversation
Thanks for trying to tackle this, but it does not fix #6947 unfortunately (there is an explicit test there: #6947 (comment)). |
I fail to see what that test has to do with cleanups. Maybe it's a test for a different issue and it should be either renamed or reported as a new one. I'm also happy to investigate it. This PR does not make that test pass, for sure, but it fixes the problem with cleanup functions not being called after a test failure and... a Anyways I'll remove the Then, can you please accept this pull request and make a new release? This is a big blocker for me and my team – and I believe for others too. Thanks a bunch! |
f35acdf
to
5dc2eed
Compare
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.
I fail to see what that test has to do with cleanups.
I agree, I left a comment there asking for clarification. 👍
This looks great to me, thanks for the PR!
Note to ourselves: we need to backport this to 5.4.x
for the next release.
changelog/6947.bugfix.rst
Outdated
@@ -0,0 +1 @@ | |||
Call cleanup functions on test failure. |
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.
Call cleanup functions on test failure. | |
Call cleanup functions of `unittest.TestCase` subclasses on test failures. |
@nicoddemus I'm up for backporting it. I'll lookup how to do it. Any links or hints? |
Thanks for the offer! Weirdly I can't find the instructions right now, but I'm sure @bluetech can point at them when he get's a chance. (Btw @bluetech just noticed that this document also needs to be updated: https://github.com/pytest-dev/pytest/blob/master/doc/en/development_guide.rst) |
Not calling cleanup functions after a test fails may affect other tests down the row. This issue was introduced in 04f27d4. When a test fails, a `_GetOutOf_testPartExecutor` exception is raised to make `unittest` halt `testPartExecutor`: https://github.com/pytest-dev/pytest/blob/413ca8a4d097ed1a98b2d1012ca7df17aa6837b1/src/_pytest/unittest.py#L206-L228 That prevents `teardown` **and** cleanup functions from being called. That's why `self._needs_explicit_tearDown` is set to `True` to then explicitly call `teardown` later on: https://github.com/pytest-dev/pytest/blob/413ca8a4d097ed1a98b2d1012ca7df17aa6837b1/src/_pytest/unittest.py#L122-L126 But no cleanup functions are called. Hence this commit.
5dc2eed
to
a3503e7
Compare
@nicoddemus |
I agree, but this still counts as a bug fix that can be released in the next patch release. Reverting it would require at least a minor version, and as I understand our users would like to get this released ASAP. Merging this now won't make reverting #6014 any harder, and we will even have a regression test to boot to prevent further mistakes. |
I agree with @nicoddemus 's assessment of the timeline. |
If you do not want to fix it proper I suggest taking #6972 instead - which basically is a revert of the "raising out of unittest". |
#6014 was meant to be a revert. All I am saying is that it fixes one symptom, but e.g. pytest-django would still be affected (if it would not monkeypatch it out already). |
So, what's the verdict? Is that one small single line so bad compared to pytest not working as it should for a particular case? Should I close this PR? What are you going to do about it? Thanks. |
Hi @scorphus, Thanks again for the PR, and sorry for the delay! We were solving some internal issues. This has been fixed (along with pdb/trace support) in #7151, which supersedes this PR. We plan to release 5.4.2 soon, probably today. 👍 Again thanks for the PR and sorry for the long response time here. |
Not calling cleanup functions after a test fails may affect other tests down the row.
This issue was introduced in 04f27d4 (
git bisect
FTW)When a test fails, a
GetOutOf_testPartExecutor
exception is raised to makeunittest
halttestPartExecutor
:pytest/src/_pytest/unittest.py
Lines 206 to 228 in 413ca8a
That prevents
teardown
and cleanup functions from being called. That's whyself._needs_explicit_tearDown
is set toTrue
to then explicitly callteardown
later on:pytest/src/_pytest/unittest.py
Lines 122 to 126 in 413ca8a
But no cleanup functions are called. Hence this PR.