From 6e7917c1a09c2174f143b34789c202a8b1a855e9 Mon Sep 17 00:00:00 2001 From: Gabriel Landau <42078554+gabriellandau@users.noreply.github.com> Date: Thu, 13 Oct 2022 18:20:46 -0400 Subject: [PATCH 1/4] Don't break into `pdb` for `raise unittest.SkipTest()` --- src/_pytest/debugging.py | 5 ++++- testing/test_debugging.py | 12 ++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/_pytest/debugging.py b/src/_pytest/debugging.py index b99c3fe2d..a3f80802c 100644 --- a/src/_pytest/debugging.py +++ b/src/_pytest/debugging.py @@ -3,6 +3,7 @@ import argparse import functools import sys import types +import unittest from typing import Any from typing import Callable from typing import Generator @@ -293,7 +294,9 @@ class PdbInvoke: sys.stdout.write(out) sys.stdout.write(err) 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: tb = _postmortem_traceback(excinfo) diff --git a/testing/test_debugging.py b/testing/test_debugging.py index 08ae09658..6761e61a9 100644 --- a/testing/test_debugging.py +++ b/testing/test_debugging.py @@ -123,6 +123,18 @@ class TestPDB: ) assert rep.skipped assert len(pdblist) == 0 + + def test_pdb_on_raise_skiptest(self, pytester, pdblist) -> None: + rep = runpdb_and_get_report( + pytester, + """ + import unittest + + raise unittest.SkipTest("This is a common way to skip an entire file.") + """, + ) + assert rep.skipped + assert len(pdblist) == 0 def test_pdb_on_BdbQuit(self, pytester, pdblist) -> None: rep = runpdb_and_get_report( From 452617686c8d08e54b9974e30c8456726f6677c5 Mon Sep 17 00:00:00 2001 From: Gabriel Landau <42078554+gabriellandau@users.noreply.github.com> Date: Fri, 14 Oct 2022 13:53:06 -0400 Subject: [PATCH 2/4] Test fix --- testing/test_debugging.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/testing/test_debugging.py b/testing/test_debugging.py index 6761e61a9..eecc1e39f 100644 --- a/testing/test_debugging.py +++ b/testing/test_debugging.py @@ -20,9 +20,18 @@ def pdb_env(request): 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) - 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] assert len(reports) == 3, reports # setup/call/teardown return reports[1] @@ -123,18 +132,16 @@ class TestPDB: ) assert rep.skipped assert len(pdblist) == 0 - - def test_pdb_on_raise_skiptest(self, pytester, pdblist) -> None: - rep = runpdb_and_get_report( + + 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 rep.skipped - assert len(pdblist) == 0 + assert "entering PDB" not in stdout, stdout def test_pdb_on_BdbQuit(self, pytester, pdblist) -> None: rep = runpdb_and_get_report( From f3d7e984abe4105c0e5c253e1b2f42be6ecae619 Mon Sep 17 00:00:00 2001 From: Gabriel Landau <42078554+gabriellandau@users.noreply.github.com> Date: Fri, 14 Oct 2022 13:58:59 -0400 Subject: [PATCH 3/4] Changelog --- changelog/10382.bugfix.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog/10382.bugfix.rst diff --git a/changelog/10382.bugfix.rst b/changelog/10382.bugfix.rst new file mode 100644 index 000000000..5876a9a43 --- /dev/null +++ b/changelog/10382.bugfix.rst @@ -0,0 +1 @@ +Do not break into pdb when ``raise unittest.SkipTest()`` appears top-level in a file. From 0bc9ffcc8782fd126d0a9ce95ce130d1d760d2cb Mon Sep 17 00:00:00 2001 From: Gabriel Landau <42078554+gabriellandau@users.noreply.github.com> Date: Fri, 14 Oct 2022 14:01:20 -0400 Subject: [PATCH 4/4] Add Gabriel Landau to AUTHORS --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index 55b0237ea..7da1f8a0c 100644 --- a/AUTHORS +++ b/AUTHORS @@ -129,6 +129,7 @@ Feng Ma Florian Bruhin Florian Dahlitz Floris Bruynooghe +Gabriel Landau Gabriel Reis Garvit Shubham Gene Wood