Skip to content

Commit c7b4b8c

Browse files
committed
test
1 parent 0ac8521 commit c7b4b8c

File tree

1 file changed

+31
-15
lines changed

1 file changed

+31
-15
lines changed

testing/test_pdb.py

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,26 @@ def runpdb_and_get_report(testdir, source):
1212
return reports[1]
1313

1414

15+
@pytest.fixture
16+
def custom_pdb_calls():
17+
called = []
18+
19+
# install dummy debugger class and track which methods were called on it
20+
class _CustomPdb:
21+
def __init__(self, *args, **kwargs):
22+
called.append("init")
23+
24+
def reset(self):
25+
called.append("reset")
26+
27+
def interaction(self, *args):
28+
called.append("interaction")
29+
30+
_pytest._CustomPdb = _CustomPdb
31+
return called
32+
33+
34+
1535
class TestPDB:
1636

1737
@pytest.fixture
@@ -334,27 +354,23 @@ def test_foo():
334354
if child.isalive():
335355
child.wait()
336356

337-
def test_pdb_custom_cls(self, testdir):
338-
called = []
339-
340-
# install dummy debugger class and track which methods were called on it
341-
class _CustomPdb:
342-
def __init__(self, *args, **kwargs):
343-
called.append("init")
344-
345-
def reset(self):
346-
called.append("reset")
347-
348-
def interaction(self, *args):
349-
called.append("interaction")
357+
def test_pdb_custom_cls(self, testdir, custom_pdb_calls):
358+
p1 = testdir.makepyfile("""xxx """)
359+
result = testdir.runpytest_inprocess(
360+
"--pdb", "--pdbcls=_pytest:_CustomPdb", p1)
361+
result.stdout.fnmatch_lines([
362+
"*NameError*xxx*",
363+
"*1 error*",
364+
])
365+
assert custom_pdb_calls == ["init", "reset", "interaction"]
350366

351-
_pytest._CustomPdb = _CustomPdb
352367

368+
def test_pdb_custom_cls_without_pdb(self, testdir, custom_pdb_calls):
353369
p1 = testdir.makepyfile("""xxx """)
354370
result = testdir.runpytest_inprocess(
355371
"--pdbcls=_pytest:_CustomPdb", p1)
356372
result.stdout.fnmatch_lines([
357373
"*NameError*xxx*",
358374
"*1 error*",
359375
])
360-
assert called == ["init", "reset", "interaction"]
376+
assert custom_pdb_calls == []

0 commit comments

Comments
 (0)