@@ -49,42 +49,18 @@ def pytest_addoption(parser):
49
49
)
50
50
51
51
52
- def _import_pdbcls (modname , classname ):
53
- try :
54
- __import__ (modname )
55
- mod = sys .modules [modname ]
56
-
57
- # Handle --pdbcls=pdb:pdb.Pdb (useful e.g. with pdbpp).
58
- parts = classname .split ("." )
59
- pdb_cls = getattr (mod , parts [0 ])
60
- for part in parts [1 :]:
61
- pdb_cls = getattr (pdb_cls , part )
62
-
63
- return pdb_cls
64
- except Exception as exc :
65
- value = ":" .join ((modname , classname ))
66
- raise UsageError ("--pdbcls: could not import {!r}: {}" .format (value , exc ))
67
-
68
-
69
52
def pytest_configure (config ):
70
- pdb_cls = config .getvalue ("usepdb_cls" )
71
- if pdb_cls :
72
- pdb_cls = _import_pdbcls (* pdb_cls )
73
- else :
74
- pdb_cls = pdb .Pdb
75
-
76
53
if config .getvalue ("trace" ):
77
54
config .pluginmanager .register (PdbTrace (), "pdbtrace" )
78
55
if config .getvalue ("usepdb" ):
79
56
config .pluginmanager .register (PdbInvoke (), "pdbinvoke" )
80
57
81
58
pytestPDB ._saved .append (
82
- (pdb .set_trace , pytestPDB ._pluginmanager , pytestPDB ._config , pytestPDB . _pdb_cls )
59
+ (pdb .set_trace , pytestPDB ._pluginmanager , pytestPDB ._config )
83
60
)
84
61
pdb .set_trace = pytestPDB .set_trace
85
62
pytestPDB ._pluginmanager = config .pluginmanager
86
63
pytestPDB ._config = config
87
- pytestPDB ._pdb_cls = pdb_cls
88
64
89
65
# NOTE: not using pytest_unconfigure, since it might get called although
90
66
# pytest_configure was not (if another plugin raises UsageError).
@@ -93,7 +69,6 @@ def fin():
93
69
pdb .set_trace ,
94
70
pytestPDB ._pluginmanager ,
95
71
pytestPDB ._config ,
96
- pytestPDB ._pdb_cls ,
97
72
) = pytestPDB ._saved .pop ()
98
73
99
74
config ._cleanup .append (fin )
@@ -104,7 +79,6 @@ class pytestPDB(object):
104
79
105
80
_pluginmanager = None
106
81
_config = None
107
- _pdb_cls = pdb .Pdb
108
82
_saved = []
109
83
_recursive_debug = 0
110
84
@@ -114,6 +88,32 @@ def _is_capturing(cls, capman):
114
88
return capman .is_capturing ()
115
89
return False
116
90
91
+ @classmethod
92
+ def _import_pdb_cls (cls ):
93
+ if cls ._config :
94
+ pdb_cls = cls ._config .getvalue ("usepdb_cls" )
95
+ if pdb_cls :
96
+ modname , classname = pdb_cls
97
+
98
+ try :
99
+ __import__ (modname )
100
+ mod = sys .modules [modname ]
101
+
102
+ # Handle --pdbcls=pdb:pdb.Pdb (useful e.g. with pdbpp).
103
+ parts = classname .split ("." )
104
+ pdb_cls = getattr (mod , parts [0 ])
105
+ for part in parts [1 :]:
106
+ pdb_cls = getattr (pdb_cls , part )
107
+
108
+ return pdb_cls
109
+ except Exception as exc :
110
+ value = ":" .join ((modname , classname ))
111
+ raise UsageError (
112
+ "--pdbcls: could not import {!r}: {}" .format (value , exc )
113
+ )
114
+
115
+ return pdb .Pdb
116
+
117
117
@classmethod
118
118
def _init_pdb (cls , * args , ** kwargs ):
119
119
""" Initialize PDB debugging, dropping any IO capturing. """
@@ -144,7 +144,9 @@ def _init_pdb(cls, *args, **kwargs):
144
144
else :
145
145
tw .sep (">" , "PDB set_trace" )
146
146
147
- class PytestPdbWrapper (cls ._pdb_cls , object ):
147
+ pdb_cls = cls ._import_pdb_cls ()
148
+
149
+ class PytestPdbWrapper (pdb_cls , object ):
148
150
_pytest_capman = capman
149
151
_continued = False
150
152
@@ -227,7 +229,8 @@ def get_stack(self, f, t):
227
229
_pdb = PytestPdbWrapper (** kwargs )
228
230
cls ._pluginmanager .hook .pytest_enter_pdb (config = cls ._config , pdb = _pdb )
229
231
else :
230
- _pdb = cls ._pdb_cls (** kwargs )
232
+ pdb_cls = cls ._import_pdb_cls ()
233
+ _pdb = pdb_cls (** kwargs )
231
234
return _pdb
232
235
233
236
@classmethod
0 commit comments