add tests to validate that --pdbcls custom debugger classes will be called when breakpoint() is used

This commit is contained in:
Anthony Shaw 2018-03-23 15:30:05 +11:00
parent 0e83e4f292
commit db581eabcb
No known key found for this signature in database
GPG Key ID: AB4A19AE1CE85744
1 changed files with 53 additions and 0 deletions

View File

@ -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):