Refactor, tests passing.
This commit is contained in:
parent
14db2f91ba
commit
9fa7745795
|
@ -129,14 +129,9 @@ class CaptureManager(object):
|
||||||
@contextlib.contextmanager
|
@contextlib.contextmanager
|
||||||
def disabled(self):
|
def disabled(self):
|
||||||
"""Context manager to temporarily disables capture."""
|
"""Context manager to temporarily disables capture."""
|
||||||
|
|
||||||
# Need to undo local capsys-et-al if exists before disabling global capture
|
# Need to undo local capsys-et-al if exists before disabling global capture
|
||||||
fixture = getattr(self._current_item, "_capture_fixture", None)
|
fixture = getattr(self._current_item, "_capture_fixture", None)
|
||||||
if fixture:
|
ctx_manager = fixture.suspend() if fixture else self._dummy_context_manager()
|
||||||
ctx_manager = fixture.disabled()
|
|
||||||
else:
|
|
||||||
ctx_manager = self._dummy_context_manager()
|
|
||||||
|
|
||||||
with ctx_manager:
|
with ctx_manager:
|
||||||
self.suspend_global_capture(item=None, in_=False)
|
self.suspend_global_capture(item=None, in_=False)
|
||||||
try:
|
try:
|
||||||
|
@ -340,7 +335,7 @@ class CaptureFixture(object):
|
||||||
return self._outerr
|
return self._outerr
|
||||||
|
|
||||||
@contextlib.contextmanager
|
@contextlib.contextmanager
|
||||||
def disabled(self):
|
def suspend(self):
|
||||||
"""Temporarily disables capture while inside the 'with' block."""
|
"""Temporarily disables capture while inside the 'with' block."""
|
||||||
self._capture.suspend_capturing()
|
self._capture.suspend_capturing()
|
||||||
try:
|
try:
|
||||||
|
@ -348,6 +343,12 @@ class CaptureFixture(object):
|
||||||
finally:
|
finally:
|
||||||
self._capture.resume_capturing()
|
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"):
|
def safe_text_dupfile(f, mode, default_encoding="UTF8"):
|
||||||
""" return an open text file object that's a duplicate of f on the
|
""" return an open text file object that's a duplicate of f on the
|
||||||
|
|
|
@ -572,11 +572,7 @@ class _LiveLoggingStreamHandler(logging.StreamHandler):
|
||||||
self._test_outcome_written = False
|
self._test_outcome_written = False
|
||||||
|
|
||||||
def emit(self, record):
|
def emit(self, record):
|
||||||
if self.capture_manager is not None:
|
ctx_manager = self.capture_manager.disabled() if self.capture_manager else _dummy_context_manager()
|
||||||
ctx_manager = self.capture_manager.disabled()
|
|
||||||
else:
|
|
||||||
ctx_manager = _dummy_context_manager()
|
|
||||||
|
|
||||||
with ctx_manager:
|
with ctx_manager:
|
||||||
if not self._first_record_emitted:
|
if not self._first_record_emitted:
|
||||||
self.stream.write("\n")
|
self.stream.write("\n")
|
||||||
|
|
Loading…
Reference in New Issue