@@ -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+
1535class TestPDB :
1636
1737 @pytest .fixture
@@ -334,27 +354,42 @@ 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 == []
377+
378+ def test_pdb_custom_cls_with_settrace (self , testdir , monkeypatch ):
379+ testdir .makepyfile (custom_pdb = """
380+ class CustomPdb:
381+ def set_trace(*args, **kwargs):
382+ print 'custom set_trace>'
383+ """ )
384+ p1 = testdir .makepyfile ("""
385+ import pytest
386+
387+ def test_foo():
388+ pytest.set_trace()
389+ """ )
390+ monkeypatch .setenv ('PYTHONPATH' , str (testdir .tmpdir ))
391+ child = testdir .spawn_pytest ("--pdbcls=custom_pdb:CustomPdb %s" % str (p1 ))
392+
393+ child .expect ('custom set_trace>' )
394+ if child .isalive ():
395+ child .wait ()
0 commit comments