diff --git a/testing/test_pdb.py b/testing/test_pdb.py index d79d71262..15cb40eb6 100644 --- a/testing/test_pdb.py +++ b/testing/test_pdb.py @@ -12,6 +12,26 @@ def runpdb_and_get_report(testdir, source): return reports[1] +@pytest.fixture +def custom_pdb_calls(): + called = [] + + # install dummy debugger class and track which methods were called on it + class _CustomPdb: + def __init__(self, *args, **kwargs): + called.append("init") + + def reset(self): + called.append("reset") + + def interaction(self, *args): + called.append("interaction") + + _pytest._CustomPdb = _CustomPdb + return called + + + class TestPDB: @pytest.fixture @@ -334,22 +354,18 @@ class TestPDB: if child.isalive(): child.wait() - def test_pdb_custom_cls(self, testdir): - called = [] + def test_pdb_custom_cls(self, testdir, custom_pdb_calls): + p1 = testdir.makepyfile("""xxx """) + result = testdir.runpytest_inprocess( + "--pdb", "--pdbcls=_pytest:_CustomPdb", p1) + result.stdout.fnmatch_lines([ + "*NameError*xxx*", + "*1 error*", + ]) + assert custom_pdb_calls == ["init", "reset", "interaction"] - # install dummy debugger class and track which methods were called on it - class _CustomPdb: - def __init__(self, *args, **kwargs): - called.append("init") - - def reset(self): - called.append("reset") - - def interaction(self, *args): - called.append("interaction") - - _pytest._CustomPdb = _CustomPdb + def test_pdb_custom_cls_without_pdb(self, testdir, custom_pdb_calls): p1 = testdir.makepyfile("""xxx """) result = testdir.runpytest_inprocess( "--pdbcls=_pytest:_CustomPdb", p1) @@ -357,4 +373,4 @@ class TestPDB: "*NameError*xxx*", "*1 error*", ]) - assert called == ["init", "reset", "interaction"] + assert custom_pdb_calls == []