Skip to content

Commit f0e4585

Browse files
authored
Merge pull request #13924 from bluetech/lazy-import-unittest
runner: don't treat `unittest.SkipTest` as an interactive exception
2 parents d587e0c + 15ab2c7 commit f0e4585

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

changelog/13917.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
:class:`unittest.SkipTest` is no longer considered an interactive exception, i.e. :hook:`pytest_exception_interact` is no longer called for it.

src/_pytest/debugging.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import sys
1212
import types
1313
from typing import Any
14-
import unittest
1514

1615
from _pytest import outcomes
1716
from _pytest._code import ExceptionInfo
@@ -295,9 +294,7 @@ def pytest_exception_interact(
295294
sys.stdout.write(out)
296295
sys.stdout.write(err)
297296
assert call.excinfo is not None
298-
299-
if not isinstance(call.excinfo.value, unittest.SkipTest):
300-
_enter_pdb(node, call.excinfo, report)
297+
_enter_pdb(node, call.excinfo, report)
301298

302299
def pytest_internalerror(self, excinfo: ExceptionInfo[BaseException]) -> None:
303300
exc_or_tb = _postmortem_exc_or_tb(excinfo)

src/_pytest/runner.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,10 @@ def check_interactive_exception(call: CallInfo[object], report: BaseReport) -> b
271271
if hasattr(report, "wasxfail"):
272272
# Exception was expected.
273273
return False
274-
if isinstance(call.excinfo.value, Skipped | bdb.BdbQuit):
274+
unittest = sys.modules.get("unittest")
275+
if isinstance(call.excinfo.value, Skipped | bdb.BdbQuit) or (
276+
unittest is not None and isinstance(call.excinfo.value, unittest.SkipTest)
277+
):
275278
# Special control flow exception.
276279
return False
277280
return True

0 commit comments

Comments
 (0)