Skip to content

Commit 3dac833

Browse files
authored
Merge pull request #10383 from gabriellandau/dont-pdb-break-for-skiptest-exceptions
2 parents 36b6384 + 0bc9ffc commit 3dac833

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

AUTHORS

+1
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ Feng Ma
129129
Florian Bruhin
130130
Florian Dahlitz
131131
Floris Bruynooghe
132+
Gabriel Landau
132133
Gabriel Reis
133134
Garvit Shubham
134135
Gene Wood

changelog/10382.bugfix.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Do not break into pdb when ``raise unittest.SkipTest()`` appears top-level in a file.

src/_pytest/debugging.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import functools
44
import sys
55
import types
6+
import unittest
67
from typing import Any
78
from typing import Callable
89
from typing import Generator
@@ -293,7 +294,9 @@ def pytest_exception_interact(
293294
sys.stdout.write(out)
294295
sys.stdout.write(err)
295296
assert call.excinfo is not None
296-
_enter_pdb(node, call.excinfo, report)
297+
298+
if not isinstance(call.excinfo.value, unittest.SkipTest):
299+
_enter_pdb(node, call.excinfo, report)
297300

298301
def pytest_internalerror(self, excinfo: ExceptionInfo[BaseException]) -> None:
299302
tb = _postmortem_traceback(excinfo)

testing/test_debugging.py

+21-2
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,18 @@ def pdb_env(request):
2020
pytester._monkeypatch.setenv("PDBPP_HIJACK_PDB", "0")
2121

2222

23-
def runpdb_and_get_report(pytester: Pytester, source: str):
23+
def runpdb(pytester: Pytester, source: str):
2424
p = pytester.makepyfile(source)
25-
result = pytester.runpytest_inprocess("--pdb", p)
25+
return pytester.runpytest_inprocess("--pdb", p)
26+
27+
28+
def runpdb_and_get_stdout(pytester: Pytester, source: str):
29+
result = runpdb(pytester, source)
30+
return result.stdout.str()
31+
32+
33+
def runpdb_and_get_report(pytester: Pytester, source: str):
34+
result = runpdb(pytester, source)
2635
reports = result.reprec.getreports("pytest_runtest_logreport") # type: ignore[attr-defined]
2736
assert len(reports) == 3, reports # setup/call/teardown
2837
return reports[1]
@@ -124,6 +133,16 @@ def test_func():
124133
assert rep.skipped
125134
assert len(pdblist) == 0
126135

136+
def test_pdb_on_top_level_raise_skiptest(self, pytester, pdblist) -> None:
137+
stdout = runpdb_and_get_stdout(
138+
pytester,
139+
"""
140+
import unittest
141+
raise unittest.SkipTest("This is a common way to skip an entire file.")
142+
""",
143+
)
144+
assert "entering PDB" not in stdout, stdout
145+
127146
def test_pdb_on_BdbQuit(self, pytester, pdblist) -> None:
128147
rep = runpdb_and_get_report(
129148
pytester,

0 commit comments

Comments
 (0)