simplify pdb disabling of capturing, also accomodate the new semantics

that capturing is always on during a test session.
This commit is contained in:
holger krekel 2014-03-14 12:49:37 +01:00
parent 9777703e03
commit ac1d277225
1 changed files with 8 additions and 21 deletions

View File

@ -16,43 +16,30 @@ def pytest_configure(config):
if config.getvalue("usepdb"): if config.getvalue("usepdb"):
config.pluginmanager.register(PdbInvoke(), 'pdbinvoke') config.pluginmanager.register(PdbInvoke(), 'pdbinvoke')
old_trace = py.std.pdb.set_trace old = (py.std.pdb.set_trace, pytestPDB._pluginmanager)
def fin(): def fin():
py.std.pdb.set_trace = old_trace py.std.pdb.set_trace, pytestPDB._pluginmanager = old
py.std.pdb.set_trace = pytest.set_trace py.std.pdb.set_trace = pytest.set_trace
pytestPDB._pluginmanager = config.pluginmanager
config._cleanup.append(fin) config._cleanup.append(fin)
class pytestPDB: class pytestPDB:
""" Pseudo PDB that defers to the real pdb. """ """ Pseudo PDB that defers to the real pdb. """
item = None _pluginmanager = None
collector = None
def set_trace(self): def set_trace(self):
""" invoke PDB set_trace debugging, dropping any IO capturing. """ """ invoke PDB set_trace debugging, dropping any IO capturing. """
frame = sys._getframe().f_back frame = sys._getframe().f_back
item = self.item or self.collector capman = None
if self._pluginmanager is not None:
if item is not None: capman = self._pluginmanager.getplugin("capturemanager")
capman = item.config.pluginmanager.getplugin("capturemanager")
if capman: if capman:
capman.reset_capturings() capman.reset_capturings()
tw = item.config.get_terminal_writer() tw = py.io.TerminalWriter()
tw.line() tw.line()
tw.sep(">", "PDB set_trace (IO-capturing turned off)") tw.sep(">", "PDB set_trace (IO-capturing turned off)")
py.std.pdb.Pdb().set_trace(frame) py.std.pdb.Pdb().set_trace(frame)
def pdbitem(item):
pytestPDB.item = item
pytest_runtest_setup = pytest_runtest_call = pytest_runtest_teardown = pdbitem
@pytest.mark.hookwrapper
def pytest_make_collect_report(collector):
pytestPDB.collector = collector
yield
pytestPDB.collector = None
def pytest_runtest_makereport():
pytestPDB.item = None
class PdbInvoke: class PdbInvoke:
def pytest_exception_interact(self, node, call, report): def pytest_exception_interact(self, node, call, report):