Skip to content

Commit 696a911

Browse files
committed
integrating review commets of @nicoddemus
plus small scale refactoring
1 parent be08223 commit 696a911

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

CHANGELOG.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818
if a test suite uses ``pytest_plugins`` to load internal plugins (`#1888`_).
1919
Thanks `@jaraco`_ for the report and `@nicoddemus`_ for the PR (`#1891`_).
2020

21-
* Do not call tearDown (and cleanups) when running unittest with ``--pdb``
21+
* Do not call tearDown and cleanups when running tests from
22+
``unittest.TestCase`` subclasses with ``--pdb``
2223
enabled. This allows proper post mortem debugging for all applications
23-
which have significant logic in their tearDown method (`#1890`_). Thanks
24+
which have significant logic in their tearDown machinery (`#1890`_). Thanks
2425
`@mbyt`_ for the PR.
2526

2627
*

_pytest/unittest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def runtest(self):
153153
if self.config.pluginmanager.get_plugin("pdbinvoke") is None:
154154
self._testcase(result=self)
155155
else:
156-
# disables tearDown and cleanups for post mortem debugging
156+
# disables tearDown and cleanups for post mortem debugging (see #1890)
157157
self._testcase.debug()
158158

159159

doc/en/unittest.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ distributing tests to multiple CPUs via the ``-nNUM`` option if you
3333
installed the ``pytest-xdist`` plugin. Please refer to
3434
the general ``pytest`` documentation for many more examples.
3535

36+
.. note::
37+
38+
Running tests from ``unittest.TestCase`` subclasses with ``--pdb`` will
39+
disable tearDown and cleanup methods for the case that an Exception is
40+
occurs. This allows proper post mortem debugging for all applications
41+
which have significant logic in their tearDown machinery.
42+
3643
Mixing pytest fixtures into unittest.TestCase style tests
3744
-----------------------------------------------------------
3845

testing/test_pdb.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,15 @@ class Blub(unittest.TestCase):
8686
def tearDown(self):
8787
self.filename = None
8888
def test_false(self):
89-
self.filename = 'bla' + '.txt'
89+
self.filename = 'debug' + '.me'
9090
assert 0
9191
""")
9292
child = testdir.spawn_pytest("--pdb %s" % p1)
9393
child.expect('(Pdb)')
9494
child.sendline('p self.filename')
9595
child.sendeof()
9696
rest = child.read().decode("utf8")
97-
assert 'bla.txt' in rest
97+
assert 'debug.me' in rest
9898
if child.isalive():
9999
child.wait()
100100

0 commit comments

Comments
 (0)