Factor out pytestPDB._is_capturing

This commit is contained in:
Daniel Hahler 2019-03-20 03:39:13 +01:00
parent d53209956b
commit 63a01bdb33
1 changed files with 11 additions and 9 deletions

View File

@ -101,6 +101,12 @@ class pytestPDB(object):
_saved = []
_recursive_debug = 0
@classmethod
def _is_capturing(cls, capman):
if capman:
return capman.is_capturing()
return False
@classmethod
def _init_pdb(cls, *args, **kwargs):
""" Initialize PDB debugging, dropping any IO capturing. """
@ -118,10 +124,7 @@ class pytestPDB(object):
if header is not None:
tw.sep(">", header)
else:
if capman:
capturing = capman.is_capturing()
else:
capturing = False
capturing = cls._is_capturing(capman)
if capturing:
if capturing == "global":
tw.sep(">", "PDB set_trace (IO-capturing turned off)")
@ -149,10 +152,9 @@ class pytestPDB(object):
if cls._recursive_debug == 0:
tw = _pytest.config.create_terminal_writer(cls._config)
tw.line()
if self._pytest_capman:
capturing = self._pytest_capman.is_capturing()
else:
capturing = False
capman = self._pytest_capman
capturing = pytestPDB._is_capturing(capman)
if capturing:
if capturing == "global":
tw.sep(">", "PDB continue (IO-capturing resumed)")
@ -162,7 +164,7 @@ class pytestPDB(object):
"PDB continue (IO-capturing resumed for %s)"
% capturing,
)
self._pytest_capman.resume()
capman.resume()
else:
tw.sep(">", "PDB continue")
cls._pluginmanager.hook.pytest_leave_pdb(