diff --git a/_pytest/debugging.py b/_pytest/debugging.py index 23d94e688..aa6311013 100644 --- a/_pytest/debugging.py +++ b/_pytest/debugging.py @@ -2,6 +2,7 @@ from __future__ import absolute_import, division, print_function import pdb import sys +from doctest import UnexpectedException def pytest_addoption(parser): @@ -95,10 +96,9 @@ def _enter_pdb(node, excinfo, rep): def _postmortem_traceback(excinfo): - # A doctest.UnexpectedException is not useful for post_mortem. - # Use the underlying exception instead: - from doctest import UnexpectedException if isinstance(excinfo.value, UnexpectedException): + # A doctest.UnexpectedException is not useful for post_mortem. + # Use the underlying exception instead: return excinfo.value.exc_info[2] else: return excinfo._excinfo[2] diff --git a/changelog/1810.bugfix b/changelog/1810.bugfix new file mode 100644 index 000000000..c91ed47d0 --- /dev/null +++ b/changelog/1810.bugfix @@ -0,0 +1 @@ +Move import of ``doctest.UnexpectedException`` to top-level to avoid possible errors when using ``--pdb``.