diff --git a/AUTHORS b/AUTHORS index 6f9197924..2d621772e 100644 --- a/AUTHORS +++ b/AUTHORS @@ -22,3 +22,4 @@ Jan Balster Grig Gheorghiu Bob Ippolito Christian Tismer +Daniel Nuri diff --git a/CHANGELOG b/CHANGELOG index 5c7a19f93..a829d18f6 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -14,6 +14,7 @@ Changes between 2.1.3 and XXX 2.2.0 - new feature to help optimizing the speed of your tests: --durations=N option for displaying N slowest test calls and setup/teardown methods. +- fix issue89: --pdb with unexpected exceptions in doctest work more sensibly - fix and cleanup pytest's own test suite to not leak FDs - fix issue83: link to generated funcarg list - fix issue74: pyarg module names are now checked against imp.find_module false positives diff --git a/_pytest/pdb.py b/_pytest/pdb.py index 1fe8dd61a..7516b14fb 100644 --- a/_pytest/pdb.py +++ b/_pytest/pdb.py @@ -70,7 +70,13 @@ class PdbInvoke: tw.sep(">", "traceback") rep.toterminal(tw) tw.sep(">", "entering PDB") - post_mortem(call.excinfo._excinfo[2]) + # A doctest.UnexpectedException is not useful for post_mortem. + # Use the underlying exception instead: + if isinstance(call.excinfo.value, py.std.doctest.UnexpectedException): + tb = call.excinfo.value.exc_info[2] + else: + tb = call.excinfo._excinfo[2] + post_mortem(tb) rep._pdbshown = True return rep diff --git a/doc/announce/release-2.2.0.txt b/doc/announce/release-2.2.0.txt index 83013a5b0..6c2bcfe8d 100644 --- a/doc/announce/release-2.2.0.txt +++ b/doc/announce/release-2.2.0.txt @@ -40,7 +40,7 @@ If you want to install or upgrade pytest you might just type:: most code probably "just" works because the hook was already called for failing setup/teardown phases of a test. -Thanks to Ronny Pfannschmidt, David Burns, Jeff Donner XXX for their +Thanks to Ronny Pfannschmidt, David Burns, Jeff Donner, Daniel Nouri, XXX for their help and feedback on various issues. best, diff --git a/testing/test_pdb.py b/testing/test_pdb.py index cd92b33d2..99903c035 100644 --- a/testing/test_pdb.py +++ b/testing/test_pdb.py @@ -106,6 +106,26 @@ class TestPDB: if child.isalive(): child.wait() + def test_pdb_interaction_doctest(self, testdir): + p1 = testdir.makepyfile(""" + import pytest + def function_1(): + ''' + >>> i = 0 + >>> assert i == 1 + ''' + """) + child = testdir.spawn_pytest("--doctest-modules --pdb %s" % p1) + child.expect("(Pdb)") + child.sendline('i') + child.expect("0") + child.expect("(Pdb)") + child.sendeof() + rest = child.read() + assert "1 failed" in rest + if child.isalive(): + child.wait() + def test_pdb_interaction_capturing_twice(self, testdir): p1 = testdir.makepyfile(""" import pytest