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

unittest runner: avoid tearDown and cleanup to ease post mortem debugging #1890

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ Martin Prusse
Matt Bachmann
Matt Williams
Matthias Hafner
mbyt
Copy link
Member

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?

Copy link
Contributor Author

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.

Michael Aquilina
Michael Birtwell
Michael Droettboom
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,22 @@
if a test suite uses ``pytest_plugins`` to load internal plugins (`#1888`_).
Thanks `@jaraco`_ for the report and `@nicoddemus`_ for the PR (`#1891`_).

* Do not call tearDown (and cleanups) when running unittest with ``--pdb``
Copy link
Member

Choose a reason for hiding this comment

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

I think we should make crystal clear that this change only affects unittest-tests, so I suggest replacing:

Do not call tearDown (and cleanups) when running unittest with --pdb

With:

Do not call tearDown and cleanups when running tests from unittest.TestCase subclasses with --pdb

enabled. This allows proper post mortem debugging for all applications
which have significant logic in their tearDown method (`#1890`_). Thanks
`@mbyt`_ for the PR.

*

.. _@joguSD: https://github.com/joguSD
.. _@AiOO: https://github.com/AiOO
.. _@mbyt: https://github.com/mbyt

.. _#1857: https://github.com/pytest-dev/pytest/issues/1857
.. _#1864: https://github.com/pytest-dev/pytest/issues/1864
.. _#1888: https://github.com/pytest-dev/pytest/issues/1888
.. _#1891: https://github.com/pytest-dev/pytest/pull/1891
.. _#1890: https://github.com/pytest-dev/pytest/issues/1890


3.0.1
Expand Down
7 changes: 6 additions & 1 deletion _pytest/unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,12 @@ def stopTest(self, testcase):
pass

def runtest(self):
self._testcase(result=self)
if self.config.pluginmanager.get_plugin("pdbinvoke") is None:
self._testcase(result=self)
else:
# disables tearDown and cleanups for post mortem debugging
Copy link
Member

Choose a reason for hiding this comment

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

Please add "(see #1890)" to this comment for future reference

self._testcase.debug()


def _prunetraceback(self, excinfo):
pytest.Function._prunetraceback(self, excinfo)
Expand Down
19 changes: 19 additions & 0 deletions testing/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,25 @@ def test_1():
if child.isalive():
child.wait()

def test_pdb_unittest_postmortem(self, testdir):
p1 = testdir.makepyfile("""
import unittest
class Blub(unittest.TestCase):
def tearDown(self):
self.filename = None
def test_false(self):
self.filename = 'bla' + '.txt'
assert 0
""")
child = testdir.spawn_pytest("--pdb %s" % p1)
child.expect('(Pdb)')
child.sendline('p self.filename')
child.sendeof()
rest = child.read().decode("utf8")
assert 'bla.txt' in rest
if child.isalive():
child.wait()

def test_pdb_interaction_capture(self, testdir):
p1 = testdir.makepyfile("""
def test_1():
Expand Down