Refactor, tests passing.

This commit is contained in:
victor 2018-08-18 13:40:08 +02:00
parent 14db2f91ba
commit 9fa7745795
2 changed files with 9 additions and 12 deletions

View File

@ -129,14 +129,9 @@ class CaptureManager(object):
@contextlib.contextmanager
def disabled(self):
"""Context manager to temporarily disables capture."""
# Need to undo local capsys-et-al if exists before disabling global capture
fixture = getattr(self._current_item, "_capture_fixture", None)
if fixture:
ctx_manager = fixture.disabled()
else:
ctx_manager = self._dummy_context_manager()
ctx_manager = fixture.suspend() if fixture else self._dummy_context_manager()
with ctx_manager:
self.suspend_global_capture(item=None, in_=False)
try:
@ -340,7 +335,7 @@ class CaptureFixture(object):
return self._outerr
@contextlib.contextmanager
def disabled(self):
def suspend(self):
"""Temporarily disables capture while inside the 'with' block."""
self._capture.suspend_capturing()
try:
@ -348,6 +343,12 @@ class CaptureFixture(object):
finally:
self._capture.resume_capturing()
@contextlib.contextmanager
def disabled(self):
capmanager = self.request.config.pluginmanager.getplugin("capturemanager")
with capmanager.disabled():
yield
def safe_text_dupfile(f, mode, default_encoding="UTF8"):
""" return an open text file object that's a duplicate of f on the

View File

@ -572,11 +572,7 @@ class _LiveLoggingStreamHandler(logging.StreamHandler):
self._test_outcome_written = False
def emit(self, record):
if self.capture_manager is not None:
ctx_manager = self.capture_manager.disabled()
else:
ctx_manager = _dummy_context_manager()
ctx_manager = self.capture_manager.disabled() if self.capture_manager else _dummy_context_manager()
with ctx_manager:
if not self._first_record_emitted:
self.stream.write("\n")