From db581eabcbc8a279020cceb5217a2ca593024aba Mon Sep 17 00:00:00 2001 From: Anthony Shaw Date: Fri, 23 Mar 2018 15:30:05 +1100 Subject: [PATCH] add tests to validate that --pdbcls custom debugger classes will be called when breakpoint() is used --- testing/test_pdb.py | 53 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/testing/test_pdb.py b/testing/test_pdb.py index c31939d7f..8051d04c3 100644 --- a/testing/test_pdb.py +++ b/testing/test_pdb.py @@ -39,6 +39,29 @@ def custom_pdb_calls(): return called +@pytest.fixture +def custom_debugger_hook(): + called = [] + + # install dummy debugger class and track which methods were called on it + class _CustomDebugger(object): + def __init__(self, *args, **kwargs): + called.append("init") + + def reset(self): + called.append("reset") + + def interaction(self, *args): + called.append("interaction") + + def set_trace(self, frame): + print("**CustomDebugger**") + called.append("set_trace") + + _pytest._CustomDebugger = _CustomDebugger + return called + + class TestPDB(object): @pytest.fixture @@ -492,6 +515,36 @@ class TestDebuggingBreakpoints(object): assert sys.breakpointhook != pytestPDB.set_trace + @pytest.mark.skipif(not SUPPORTS_BREAKPOINT_BUILTIN, reason="Requires breakpoint() builtin") + def test_sys_breakpointhook_configure_and_unconfigure_with_pdb_flag(self, testdir): + config = testdir.parseconfig() + + pytest_configure(config) + assert sys.breakpointhook == pytestPDB.set_trace + + p1 = testdir.makepyfile(""" + def test_nothing(): + a = 0 + assert a == 0 + """) + result = testdir.runpytest_inprocess("--pdb", p1) + assert sys.breakpointhook != pytestPDB.set_trace + + @pytest.mark.skipif(not SUPPORTS_BREAKPOINT_BUILTIN, reason="Requires breakpoint() builtin") + def test_pdb_custom_cls(self, testdir, custom_debugger_hook): + p1 = testdir.makepyfile(""" + def test_nothing(): + breakpoint() + """) + result = testdir.runpytest_inprocess( + "--pdb", "--pdbcls=_pytest:_CustomDebugger", p1) + result.stdout.fnmatch_lines([ + "*CustomDebugger*", + "*1 passed*", + ]) + assert custom_debugger_hook == ["init", "set_trace"] + + @pytest.mark.skipif(not SUPPORTS_BREAKPOINT_BUILTIN, reason="Requires breakpoint() builtin") @pytest.mark.skipif(not _ENVIRON_PYTHONBREAKPOINT=='', reason="Requires breakpoint() default value") def test_sys_breakpoint_interception(self, testdir):