From 2a1b1107c5395560e7335ab0ef775343b3f65566 Mon Sep 17 00:00:00 2001 From: Brian Maissy Date: Thu, 25 Jan 2018 22:28:27 +0200 Subject: [PATCH 1/3] If we fail to import doctest.UnexpectedException during postmortem, fail quietly and continue --- _pytest/debugging.py | 18 +++++++++++------- changelog/1810.bugfix | 1 + 2 files changed, 12 insertions(+), 7 deletions(-) create mode 100644 changelog/1810.bugfix diff --git a/_pytest/debugging.py b/_pytest/debugging.py index d7dca7809..e458406b5 100644 --- a/_pytest/debugging.py +++ b/_pytest/debugging.py @@ -95,13 +95,17 @@ 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): - return excinfo.value.exc_info[2] - else: - return excinfo._excinfo[2] + try: + 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] + except ImportError: + # If we fail to import, continue quietly (if we ran out of file descriptors, for example: #1810) + pass + + return excinfo._excinfo[2] def _find_last_non_hidden_frame(stack): diff --git a/changelog/1810.bugfix b/changelog/1810.bugfix new file mode 100644 index 000000000..6e9389671 --- /dev/null +++ b/changelog/1810.bugfix @@ -0,0 +1 @@ +If we fail to import doctest.UnexpectedException during postmortem, fail quietly and continue. \ No newline at end of file From 867344d0d72cfe79bb5ff316b065621f12627f40 Mon Sep 17 00:00:00 2001 From: Brian Maissy Date: Sun, 4 Feb 2018 00:03:17 +0200 Subject: [PATCH 2/3] move import to top --- _pytest/debugging.py | 18 +++++++----------- changelog/1810.bugfix | 2 +- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/_pytest/debugging.py b/_pytest/debugging.py index e458406b5..bd7a33b2d 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,17 +96,12 @@ def _enter_pdb(node, excinfo, rep): def _postmortem_traceback(excinfo): - try: - 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] - except ImportError: - # If we fail to import, continue quietly (if we ran out of file descriptors, for example: #1810) - pass - - return excinfo._excinfo[2] + 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] def _find_last_non_hidden_frame(stack): diff --git a/changelog/1810.bugfix b/changelog/1810.bugfix index 6e9389671..5c3000d05 100644 --- a/changelog/1810.bugfix +++ b/changelog/1810.bugfix @@ -1 +1 @@ -If we fail to import doctest.UnexpectedException during postmortem, fail quietly and continue. \ No newline at end of file +Move import of doctest.UnexpectedException to top-level. \ No newline at end of file From ea8997a108eb78a795f461ff1f41e0771e58c2d7 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Sat, 3 Feb 2018 20:21:06 -0200 Subject: [PATCH 3/3] Update wording in CHANGELOG --- changelog/1810.bugfix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog/1810.bugfix b/changelog/1810.bugfix index 5c3000d05..c91ed47d0 100644 --- a/changelog/1810.bugfix +++ b/changelog/1810.bugfix @@ -1 +1 @@ -Move import of doctest.UnexpectedException to top-level. \ No newline at end of file +Move import of ``doctest.UnexpectedException`` to top-level to avoid possible errors when using ``--pdb``.