Merge pull request #10383 from gabriellandau/dont-pdb-break-for-skiptest-exceptions
This commit is contained in:
commit
3dac833a52
1
AUTHORS
1
AUTHORS
|
@ -129,6 +129,7 @@ Feng Ma
|
||||||
Florian Bruhin
|
Florian Bruhin
|
||||||
Florian Dahlitz
|
Florian Dahlitz
|
||||||
Floris Bruynooghe
|
Floris Bruynooghe
|
||||||
|
Gabriel Landau
|
||||||
Gabriel Reis
|
Gabriel Reis
|
||||||
Garvit Shubham
|
Garvit Shubham
|
||||||
Gene Wood
|
Gene Wood
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Do not break into pdb when ``raise unittest.SkipTest()`` appears top-level in a file.
|
|
@ -3,6 +3,7 @@ import argparse
|
||||||
import functools
|
import functools
|
||||||
import sys
|
import sys
|
||||||
import types
|
import types
|
||||||
|
import unittest
|
||||||
from typing import Any
|
from typing import Any
|
||||||
from typing import Callable
|
from typing import Callable
|
||||||
from typing import Generator
|
from typing import Generator
|
||||||
|
@ -293,7 +294,9 @@ class PdbInvoke:
|
||||||
sys.stdout.write(out)
|
sys.stdout.write(out)
|
||||||
sys.stdout.write(err)
|
sys.stdout.write(err)
|
||||||
assert call.excinfo is not None
|
assert call.excinfo is not None
|
||||||
_enter_pdb(node, call.excinfo, report)
|
|
||||||
|
if not isinstance(call.excinfo.value, unittest.SkipTest):
|
||||||
|
_enter_pdb(node, call.excinfo, report)
|
||||||
|
|
||||||
def pytest_internalerror(self, excinfo: ExceptionInfo[BaseException]) -> None:
|
def pytest_internalerror(self, excinfo: ExceptionInfo[BaseException]) -> None:
|
||||||
tb = _postmortem_traceback(excinfo)
|
tb = _postmortem_traceback(excinfo)
|
||||||
|
|
|
@ -20,9 +20,18 @@ def pdb_env(request):
|
||||||
pytester._monkeypatch.setenv("PDBPP_HIJACK_PDB", "0")
|
pytester._monkeypatch.setenv("PDBPP_HIJACK_PDB", "0")
|
||||||
|
|
||||||
|
|
||||||
def runpdb_and_get_report(pytester: Pytester, source: str):
|
def runpdb(pytester: Pytester, source: str):
|
||||||
p = pytester.makepyfile(source)
|
p = pytester.makepyfile(source)
|
||||||
result = pytester.runpytest_inprocess("--pdb", p)
|
return pytester.runpytest_inprocess("--pdb", p)
|
||||||
|
|
||||||
|
|
||||||
|
def runpdb_and_get_stdout(pytester: Pytester, source: str):
|
||||||
|
result = runpdb(pytester, source)
|
||||||
|
return result.stdout.str()
|
||||||
|
|
||||||
|
|
||||||
|
def runpdb_and_get_report(pytester: Pytester, source: str):
|
||||||
|
result = runpdb(pytester, source)
|
||||||
reports = result.reprec.getreports("pytest_runtest_logreport") # type: ignore[attr-defined]
|
reports = result.reprec.getreports("pytest_runtest_logreport") # type: ignore[attr-defined]
|
||||||
assert len(reports) == 3, reports # setup/call/teardown
|
assert len(reports) == 3, reports # setup/call/teardown
|
||||||
return reports[1]
|
return reports[1]
|
||||||
|
@ -124,6 +133,16 @@ class TestPDB:
|
||||||
assert rep.skipped
|
assert rep.skipped
|
||||||
assert len(pdblist) == 0
|
assert len(pdblist) == 0
|
||||||
|
|
||||||
|
def test_pdb_on_top_level_raise_skiptest(self, pytester, pdblist) -> None:
|
||||||
|
stdout = runpdb_and_get_stdout(
|
||||||
|
pytester,
|
||||||
|
"""
|
||||||
|
import unittest
|
||||||
|
raise unittest.SkipTest("This is a common way to skip an entire file.")
|
||||||
|
""",
|
||||||
|
)
|
||||||
|
assert "entering PDB" not in stdout, stdout
|
||||||
|
|
||||||
def test_pdb_on_BdbQuit(self, pytester, pdblist) -> None:
|
def test_pdb_on_BdbQuit(self, pytester, pdblist) -> None:
|
||||||
rep = runpdb_and_get_report(
|
rep = runpdb_and_get_report(
|
||||||
pytester,
|
pytester,
|
||||||
|
|
Loading…
Reference in New Issue