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