8
8
9
9
def pytest_addoption (parser ):
10
10
group = parser .getgroup ("general" )
11
- group ._addoption ('--pdb' ,
12
- action = "store_true" , dest = "usepdb" , default = False ,
13
- help = "start the interactive Python debugger on errors." )
11
+ group ._addoption (
12
+ '--pdb' , dest = "usepdb" , action = "store_true" ,
13
+ help = "start the interactive Python debugger on errors." )
14
+ group ._addoption (
15
+ '--pdbcls' , dest = "usepdb_cls" , metavar = "modulename:classname" ,
16
+ help = "start a custom interactive Python debugger on errors." )
14
17
15
18
def pytest_namespace ():
16
19
return {'set_trace' : pytestPDB ().set_trace }
17
20
18
21
def pytest_configure (config ):
19
- if config .getvalue ("usepdb" ):
22
+ if config .getvalue ("usepdb" ) or config . getvalue ( "usepdb_cls" ) :
20
23
config .pluginmanager .register (PdbInvoke (), 'pdbinvoke' )
24
+ if config .getvalue ("usepdb_cls" ):
25
+ modname , classname = config .getvalue ("usepdb_cls" ).split (":" )
26
+ __import__ (modname )
27
+ pdb_cls = getattr (sys .modules [modname ], classname )
28
+ else :
29
+ pdb_cls = pdb .Pdb
30
+ pytestPDB ._pdb_cls = pdb_cls
21
31
22
32
old = (pdb .set_trace , pytestPDB ._pluginmanager )
23
33
def fin ():
24
34
pdb .set_trace , pytestPDB ._pluginmanager = old
25
35
pytestPDB ._config = None
36
+ pytestPDB ._pdb_cls = pdb .Pdb
26
37
pdb .set_trace = pytest .set_trace
27
38
pytestPDB ._pluginmanager = config .pluginmanager
28
39
pytestPDB ._config = config
@@ -32,6 +43,7 @@ class pytestPDB:
32
43
""" Pseudo PDB that defers to the real pdb. """
33
44
_pluginmanager = None
34
45
_config = None
46
+ _pdb_cls = pdb .Pdb
35
47
36
48
def set_trace (self ):
37
49
""" invoke PDB set_trace debugging, dropping any IO capturing. """
@@ -45,7 +57,7 @@ def set_trace(self):
45
57
tw .line ()
46
58
tw .sep (">" , "PDB set_trace (IO-capturing turned off)" )
47
59
self ._pluginmanager .hook .pytest_enter_pdb (config = self ._config )
48
- pdb . Pdb ().set_trace (frame )
60
+ self . _pdb_cls ().set_trace (frame )
49
61
50
62
51
63
class PdbInvoke :
@@ -98,7 +110,7 @@ def _find_last_non_hidden_frame(stack):
98
110
99
111
100
112
def post_mortem (t ):
101
- class Pdb (pdb . Pdb ):
113
+ class Pdb (pytestPDB . _pdb_cls ):
102
114
def get_stack (self , f , t ):
103
115
stack , i = pdb .Pdb .get_stack (self , f , t )
104
116
if f is None :
0 commit comments