Skip to content

Commit 565f4cb

Browse files
authored
Merge pull request #7248 from asottile/backport-7244
[5.4.x] Merge pull request #7244 from DahlitzFlorian/fix-issue-7150
2 parents 2fb2962 + af6548a commit 565f4cb

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

changelog/7150.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Prevent hiding the underlying exception when ``ConfTestImportFailure`` is raised.

src/_pytest/debugging.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import sys
55

66
from _pytest import outcomes
7+
from _pytest.config import ConftestImportFailure
78
from _pytest.config import hookimpl
89
from _pytest.config.exceptions import UsageError
910

@@ -338,6 +339,10 @@ def _postmortem_traceback(excinfo):
338339
# A doctest.UnexpectedException is not useful for post_mortem.
339340
# Use the underlying exception instead:
340341
return excinfo.value.exc_info[2]
342+
elif isinstance(excinfo.value, ConftestImportFailure):
343+
# A config.ConftestImportFailure is not useful for post_mortem.
344+
# Use the underlying exception instead:
345+
return excinfo.value.excinfo[2]
341346
else:
342347
return excinfo._excinfo[2]
343348

testing/test_debugging.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,15 @@ def pytest_runtest_protocol():
342342
child.sendeof()
343343
self.flush(child)
344344

345+
def test_pdb_prevent_ConftestImportFailure_hiding_exception(self, testdir):
346+
testdir.makepyfile("def test_func(): pass")
347+
sub_dir = testdir.tmpdir.join("ns").ensure_dir()
348+
sub_dir.join("conftest").new(ext=".py").write("import unknown")
349+
sub_dir.join("test_file").new(ext=".py").write("def test_func(): pass")
350+
351+
result = testdir.runpytest_subprocess("--pdb", ".")
352+
result.stdout.fnmatch_lines(["-> import unknown"])
353+
345354
def test_pdb_interaction_capturing_simple(self, testdir):
346355
p1 = testdir.makepyfile(
347356
"""

0 commit comments

Comments
 (0)