-
-
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
unittest runner: avoid tearDown and cleanup to ease post mortem debugging #1890
unittest runner: avoid tearDown and cleanup to ease post mortem debugging #1890
Conversation
Please let me know what you think about the problem. Is there another / more simple solution to this problem? In case the proposed solution is sensible, I'll add a corresponding test. |
Hey @mbyt, thanks for the PR. TBH I'm reluctant of adding such an esoteric use-case to pytest core, specially on the You can accomplish something similar by adding this to your def pytest_configure(config):
if config.getvalue("usepdb"):
import _pytest.unittest
_pytest.unittest.TestCaseFunction.runtest = lambda self,*args,**kw: self._testcase.debug() |
Hmm now that I thought a little more and played around a bit, I think actually we somehow should make it possible to use Consider: import unittest
class Test(unittest.TestCase):
def tearDown(self):
self.filename = None
def test_1(self):
assert 1
def test_2(self):
self.filename = 'debug me'
assert 0 If One might even argue that What do others think? |
i believe this is something we want to add, but it should be accompanied with a test so we dont break it |
…tem_debugging Conflicts: CHANGELOG.rst
Thank you very much for your insights and your fast reply. I added a corresponding test. Another possible solution would be to read the |
@@ -91,6 +91,7 @@ Martin Prusse | |||
Matt Bachmann | |||
Matt Williams | |||
Matthias Hafner | |||
mbyt |
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.
Don't you want to use your real name here?
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.
Thanks for letting me know. If you do not mind, let's leave it like this.
Thanks! 😁 Other than my comments above, would you mind adding a small blurb to the docs mentioning this change? I think adding a |
plus small scale refactoring
@nicoddemus thanks again for looking at the changesets and your constructive comments. I modified the code accordingly. |
Thanks again! |
Just stumbled across this via #1932.
Why is pdb not invoked before the teardown, if the error is before it? |
Ok, current code looks a bit differrent: It might be fine then - let's followup on #1932 / close it if fixed. |
Reverts pytest-dev#1890, which needs to be fixed/addressed in another way (pytest-dev#5996). Fixes pytest-dev#5991.
#5996 fixes this. |
Reverts pytest-dev#1890, which needs to be fixed/addressed in another way (pytest-dev#5996). Fixes pytest-dev#5991.
Reverts pytest-dev#1890, which needs to be fixed/addressed in another way (pytest-dev#5996). Fixes pytest-dev#5991.
Fixes pytest-dev#5991 Fixes pytest-dev#3823 Ref: pytest-dev/pytest-django#772 Ref: pytest-dev#1890 Ref: pytest-dev/pytest-django#782 - inject wrapped testMethod - adjust test_trial_error - add test for `--trace` with unittests
Fixes pytest-dev#5991 Fixes pytest-dev#3823 Ref: pytest-dev/pytest-django#772 Ref: pytest-dev#1890 Ref: pytest-dev/pytest-django#782 - inject wrapped testMethod - adjust test_trial_error - add test for `--trace` with unittests
Fixes pytest-dev#5991 Fixes pytest-dev#3823 Ref: pytest-dev/pytest-django#772 Ref: pytest-dev#1890 Ref: pytest-dev/pytest-django#782 - inject wrapped testMethod - adjust test_trial_error - add test for `--trace` with unittests
Fixes pytest-dev#5991 Fixes pytest-dev#3823 Ref: pytest-dev/pytest-django#772 Ref: pytest-dev#1890 Ref: pytest-dev/pytest-django#782 - inject wrapped testMethod - adjust test_trial_error - add test for `--trace` with unittests
Fixes pytest-dev#5991 Fixes pytest-dev#3823 Ref: pytest-dev/pytest-django#772 Ref: pytest-dev#1890 Ref: pytest-dev/pytest-django#782 - inject wrapped testMethod - adjust test_trial_error - add test for `--trace` with unittests
Fixes pytest-dev#5991 Fixes pytest-dev#3823 Ref: pytest-dev/pytest-django#772 Ref: pytest-dev#1890 Ref: pytest-dev/pytest-django#782 - inject wrapped testMethod - adjust test_trial_error - add test for `--trace` with unittests
Fixes pytest-dev#5991 Fixes pytest-dev#3823 Ref: pytest-dev/pytest-django#772 Ref: pytest-dev#1890 Ref: pytest-dev/pytest-django#782 - inject wrapped testMethod - adjust test_trial_error - add test for `--trace` with unittests
Fixes pytest-dev#5991 Fixes pytest-dev#3823 Ref: pytest-dev/pytest-django#772 Ref: pytest-dev#1890 Ref: pytest-dev/pytest-django#782 - inject wrapped testMethod - adjust test_trial_error - add test for `--trace` with unittests
Fixes pytest-dev#5991 Fixes pytest-dev#3823 Ref: pytest-dev/pytest-django#772 Ref: pytest-dev#1890 Ref: pytest-dev/pytest-django#782 - inject wrapped testMethod - adjust test_trial_error - add test for `--trace` with unittests
Fixes pytest-dev#5991 Fixes pytest-dev#3823 Ref: pytest-dev/pytest-django#772 Ref: pytest-dev#1890 Ref: pytest-dev/pytest-django#782 - inject wrapped testMethod - adjust test_trial_error - add test for `--trace` with unittests
Assuming pytest is used to run a GUI test unittest suite. Typically GUI tests close the GUI in the unittest tearDowns or cleanup methods.
These tests cannot be easily post mortem debugged (
pytest --pdb
), as unittests tearDown and cleanup (which close the GUI) are called on an exception before the post mortem debugger jumps into place. Therefore, the GUI is closed and no direct interaction is possible any more.A work around when running the unittest via the unittest runner is to add the following line to ~/.pdbrc:
!import unittest; unittest.TestCase.run = lambda self,*args,**kw: unittest.TestCase.debug(self)
, start the tests withpython -m pdb test.py
and hit continue.This pull request accomplishes the same within the pytest unittest compatibility layer. It is solely activated if pytest ist called with --pdb.
An example program which shows the problem would be the following (run with and without this change):