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

Fix cleanup functions not being invoked on test failures #7151

Merged
merged 2 commits into from May 2, 2020

Conversation

nicoddemus
Copy link
Member

Fix #6947

Copy link
Member

@RonnyPfannschmidt RonnyPfannschmidt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its generally a good idea to unify the wrapping

its unfortunate the async cant be integrated easily/sanely

src/_pytest/unittest.py Show resolved Hide resolved
@@ -537,28 +537,24 @@ def f(_):
)
result.stdout.fnmatch_lines(
[
"test_trial_error.py::TC::test_four SKIPPED",
"test_trial_error.py::TC::test_four FAILED",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reverts the test to the state before 04f27d4, which introduced the breaking change about addCleanup not being called properly for failed tests.

@nicoddemus nicoddemus added the needs backport applied to PRs, indicates that it should be ported to the current bug-fix branch label May 1, 2020
@nicoddemus nicoddemus force-pushed the unittest-cleanup-6947 branch 2 times, most recently from 20ac646 to e244e32 Compare May 2, 2020 14:22

# let the unittest framework handle async functions
if is_async_function(self.obj):
self._testcase(self)
else:
setattr(self._testcase, self._testcase._testMethodName, wrapped_testMethod)
# when --pdb is given, we want to postpone calling tearDown() otherwise
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please review this bit @RonnyPfannschmidt? I noticed this was needed after one of the tests failed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm actually YOLO on that one, my insight to the implementation of unittest is limited

src/_pytest/unittest.py Outdated Show resolved Hide resolved

# let the unittest framework handle async functions
if is_async_function(self.obj):
self._testcase(self)
else:
setattr(self._testcase, self._testcase._testMethodName, wrapped_testMethod)
# when --pdb is given, we want to postpone calling tearDown() otherwise
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm actually YOLO on that one, my insight to the implementation of unittest is limited

Also delay calling tearDown() when --pdb is given, so users still have
access to the instance variables (which are usually cleaned up during tearDown())
when debugging.

Fix pytest-dev#6947
This reverts the test to the state before 04f27d4, which introduced the breaking
change about addCleanup not being called properly for failed tests.
@nicoddemus
Copy link
Member Author

Thanks @RonnyPfannschmidt!

@nicoddemus nicoddemus merged commit 3312820 into pytest-dev:master May 2, 2020
@nicoddemus nicoddemus deleted the unittest-cleanup-6947 branch May 2, 2020 18:43
nicoddemus added a commit to nicoddemus/pytest that referenced this pull request May 2, 2020
@nicoddemus nicoddemus added backported PR has been backported to the current bug-fix branch and removed needs backport applied to PRs, indicates that it should be ported to the current bug-fix branch labels May 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backported PR has been backported to the current bug-fix branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

unittest.TestCase cleanup functions not invoked on test failure
2 participants