"suspend" method of capture fixture private

Also change the context-manager to global_and_fixture_disabled to
better convey its meaning
This commit is contained in:
Bruno Oliveira 2018-08-18 11:36:24 -03:00
parent f674217c43
commit 5cf7d1dba2
3 changed files with 9 additions and 8 deletions

View File

@ -122,11 +122,11 @@ class CaptureManager(object):
return outerr return outerr
@contextlib.contextmanager @contextlib.contextmanager
def disabled(self): def global_and_fixture_disabled(self):
"""Context manager to temporarily disables capture.""" """Context manager to temporarily disables global and current fixture capturing."""
# 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)
ctx_manager = fixture.suspend() if fixture else dummy_context_manager() ctx_manager = fixture._suspend() if fixture else 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:
@ -333,8 +333,8 @@ class CaptureFixture(object):
return self._outerr return self._outerr
@contextlib.contextmanager @contextlib.contextmanager
def suspend(self): def _suspend(self):
"""Temporarily disables capture while inside the 'with' block.""" """Suspends this fixture's own capturing temporarily."""
self._capture.suspend_capturing() self._capture.suspend_capturing()
try: try:
yield yield
@ -343,8 +343,9 @@ class CaptureFixture(object):
@contextlib.contextmanager @contextlib.contextmanager
def disabled(self): def disabled(self):
"""Temporarily disables capture while inside the 'with' block."""
capmanager = self.request.config.pluginmanager.getplugin("capturemanager") capmanager = self.request.config.pluginmanager.getplugin("capturemanager")
with capmanager.disabled(): with capmanager.global_and_fixture_disabled():
yield yield

View File

@ -569,7 +569,7 @@ class _LiveLoggingStreamHandler(logging.StreamHandler):
def emit(self, record): def emit(self, record):
ctx_manager = ( ctx_manager = (
self.capture_manager.disabled() self.capture_manager.global_and_fixture_disabled()
if self.capture_manager if self.capture_manager
else dummy_context_manager() else dummy_context_manager()
) )

View File

@ -885,7 +885,7 @@ def test_live_logging_suspends_capture(has_capture_manager, request):
calls = [] calls = []
@contextlib.contextmanager @contextlib.contextmanager
def disabled(self): def global_and_fixture_disabled(self):
self.calls.append("enter disabled") self.calls.append("enter disabled")
yield yield
self.calls.append("exit disabled") self.calls.append("exit disabled")