Skip to content

Commit

Permalink
Merge pull request #7248 from asottile/backport-7244
Browse files Browse the repository at this point in the history
[5.4.x] Merge pull request #7244 from DahlitzFlorian/fix-issue-7150
  • Loading branch information
asottile authored May 23, 2020
2 parents 2fb2962 + af6548a commit 565f4cb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog/7150.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Prevent hiding the underlying exception when ``ConfTestImportFailure`` is raised.
5 changes: 5 additions & 0 deletions src/_pytest/debugging.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import sys

from _pytest import outcomes
from _pytest.config import ConftestImportFailure
from _pytest.config import hookimpl
from _pytest.config.exceptions import UsageError

Expand Down Expand Up @@ -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]

Expand Down
9 changes: 9 additions & 0 deletions testing/test_debugging.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,15 @@ def pytest_runtest_protocol():
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(
"""
Expand Down

0 comments on commit 565f4cb

Please sign in to comment.