-
-
Notifications
You must be signed in to change notification settings - Fork 31k
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
TestCase: call _post_teardown always when _pre_setup worked #11938
Conversation
This is in line with unittest itself calling `TearDown` when `SetUp` succeeded.
@felixxm |
@blueyed thanks for looking into this. Can you please add more details on what this aims to address, and point us to the place in It seems to me that While I do understand the pain of having a non-rolled-back Django DB after a failing/skipped test, I'm not sure I agree with this change. Calling Shouldn't this be handled in the runner instead? If I understand the design in By the way, I'm not sure that References:
|
Yes. Therefore it is not really needed/useful indeed, closing for now. This resulted from when I've looked into issues with pytest-django, which only happen in the first place because pytest itself calls |
Well, OTOH I've tried to mimic the behavior that TearDown gets called after SetUp always (in non-debug mode), which is not the case with Therefore re-opening - it was just driven by making Django behave like unittest in this regard. I.e. the added test would fail, which means that |
super().debug() | ||
else: | ||
super().__call__(result) | ||
except BaseException: |
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.
It seems to me that SkipTest
is the only exception that should be handled when skipping with debug=True
.
Also, do we need to actually wrap the call super().__call__(result)
, given that _Outcome.testPartExecutor
already catches all exceptions, nothing can be raised here (unless it's an exception happening before or after the setup/test/teardown flow).
It's important to note that it's possible to call SkipError
from setUp and tearDown, so if we want to support the same in Django's _pre_setup
and _post_teardown
we should catch SkipTest
exception here as well...
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.
It seems to me that
SkipTest
is the only exception that should be handled when skipping withdebug=True
.Also, do we need to actually wrap the call
super().__call__(result)
, given that_Outcome.testPartExecutor
already catches all exceptions, nothing can be raised here (unless it's an exception happening before or after the setup/test/teardown flow).
I agree with these comments ☝️ .
It's important to note that it's possible to call
SkipError
from setUp and tearDown, so if we want to support the same in Django's_pre_setup
and_post_teardown
we should catchSkipTest
exception here as well...
I'm not sure about this. What steps should we take if someone calls skipTest()
in _pre_setup()
or _post_teardown()
?
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.
Sorry for not following up earlier.
JFI: pytest actually tries hard getting out of testPartExecutor, which causes _post_teardown
not being called now with pytest 5.4 (via pytest-django, pytest-dev/pytest-django#824).
IIRC I've done this PR initially when I've looked at Django's code, without having in mind that pytest might end up doing it this way.
The new test doesn't use result = _DebugResult()
test_suite.run(result, debug=True) instead of It's strictly related with the previous fix, so we can use |
Oh, I must have missed this then - I've pretty sure to have checked that it failed without the patch - or isn't that what you've meant? |
Yes, exactly |
Oh.. 😕 - pushed a fixup. |
@blueyed Are you going to address these suggestions and questions? Please add |
Closing due to inactivity. |
This is in line with unittest itself calling
TearDown
whenSetUp
succeeded.
Ref/via: pytest-dev/pytest-django#772