From d0eb86cfa671057c678a90ac10c1a43be11bdf6a Mon Sep 17 00:00:00 2001 From: Florian Dahlitz Date: Fri, 22 May 2020 22:58:35 +0200 Subject: [PATCH 1/2] Prevent hiding underlying exception when ConfTestImportFailure is raised --- changelog/7150.bugfix.rst | 1 + src/_pytest/debugging.py | 5 +++++ 2 files changed, 6 insertions(+) create mode 100644 changelog/7150.bugfix.rst diff --git a/changelog/7150.bugfix.rst b/changelog/7150.bugfix.rst new file mode 100644 index 000000000..42cf5c7d2 --- /dev/null +++ b/changelog/7150.bugfix.rst @@ -0,0 +1 @@ +Prevent hiding the underlying exception when ``ConfTestImportFailure`` is raised. diff --git a/src/_pytest/debugging.py b/src/_pytest/debugging.py index 17915db73..26c3095dc 100644 --- a/src/_pytest/debugging.py +++ b/src/_pytest/debugging.py @@ -4,6 +4,7 @@ import functools import sys from _pytest import outcomes +from _pytest.config import ConftestImportFailure from _pytest.config import hookimpl from _pytest.config.exceptions import UsageError @@ -338,6 +339,10 @@ def _postmortem_traceback(excinfo): # A doctest.UnexpectedException is not useful for post_mortem. # Use the underlying exception instead: return excinfo.value.exc_info[2] + elif isinstance(excinfo.value, ConftestImportFailure): + # A config.ConftestImportFailure is not useful for post_mortem. + # Use the underlying exception instead: + return excinfo.value.excinfo[2] else: return excinfo._excinfo[2] From 35e6dd01173de0b58e175d79e58d6295c359a0bd Mon Sep 17 00:00:00 2001 From: Florian Dahlitz Date: Sat, 23 May 2020 18:19:33 +0200 Subject: [PATCH 2/2] Add test for exposure of underlying exception --- testing/test_debugging.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/testing/test_debugging.py b/testing/test_debugging.py index 719d6477b..00af4a088 100644 --- a/testing/test_debugging.py +++ b/testing/test_debugging.py @@ -342,6 +342,15 @@ class TestPDB: child.sendeof() self.flush(child) + def test_pdb_prevent_ConftestImportFailure_hiding_exception(self, testdir): + testdir.makepyfile("def test_func(): pass") + sub_dir = testdir.tmpdir.join("ns").ensure_dir() + sub_dir.join("conftest").new(ext=".py").write("import unknown") + sub_dir.join("test_file").new(ext=".py").write("def test_func(): pass") + + result = testdir.runpytest_subprocess("--pdb", ".") + result.stdout.fnmatch_lines(["-> import unknown"]) + def test_pdb_interaction_capturing_simple(self, testdir): p1 = testdir.makepyfile( """