Merge pull request #1890 from mbyt/disable_tearDown_and_cleanups_for_post_mortem_debugging
unittest runner: avoid tearDown and cleanup to ease post mortem debugging
This commit is contained in:
commit
a094fb3aa6
1
AUTHORS
1
AUTHORS
|
@ -91,6 +91,7 @@ Martin Prusse
|
|||
Matt Bachmann
|
||||
Matt Williams
|
||||
Matthias Hafner
|
||||
mbyt
|
||||
Michael Aquilina
|
||||
Michael Birtwell
|
||||
Michael Droettboom
|
||||
|
|
|
@ -18,15 +18,23 @@
|
|||
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 tests from
|
||||
``unittest.TestCase`` subclasses with ``--pdb``
|
||||
enabled. This allows proper post mortem debugging for all applications
|
||||
which have significant logic in their tearDown machinery (`#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
|
||||
|
|
|
@ -150,7 +150,12 @@ class TestCaseFunction(pytest.Function):
|
|||
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 (see #1890)
|
||||
self._testcase.debug()
|
||||
|
||||
|
||||
def _prunetraceback(self, excinfo):
|
||||
pytest.Function._prunetraceback(self, excinfo)
|
||||
|
|
|
@ -33,6 +33,13 @@ distributing tests to multiple CPUs via the ``-nNUM`` option if you
|
|||
installed the ``pytest-xdist`` plugin. Please refer to
|
||||
the general ``pytest`` documentation for many more examples.
|
||||
|
||||
.. note::
|
||||
|
||||
Running tests from ``unittest.TestCase`` subclasses with ``--pdb`` will
|
||||
disable tearDown and cleanup methods for the case that an Exception
|
||||
occurs. This allows proper post mortem debugging for all applications
|
||||
which have significant logic in their tearDown machinery.
|
||||
|
||||
Mixing pytest fixtures into unittest.TestCase style tests
|
||||
-----------------------------------------------------------
|
||||
|
||||
|
|
|
@ -79,6 +79,25 @@ class TestPDB:
|
|||
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 = 'debug' + '.me'
|
||||
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 'debug.me' in rest
|
||||
if child.isalive():
|
||||
child.wait()
|
||||
|
||||
def test_pdb_interaction_capture(self, testdir):
|
||||
p1 = testdir.makepyfile("""
|
||||
def test_1():
|
||||
|
|
Loading…
Reference in New Issue