Fixed global not called if no capsys fixture. Using now capsys context manager as well.

This commit is contained in:
victor 2018-08-18 12:16:47 +02:00
parent 090f67a980
commit 14db2f91ba
1 changed files with 17 additions and 17 deletions

View File

@ -121,25 +121,28 @@ class CaptureManager(object):
finally: finally:
cap.suspend_capturing(in_=in_) cap.suspend_capturing(in_=in_)
return outerr return outerr
@contextlib.contextmanager
def _dummy_context_manager(self):
yield
@contextlib.contextmanager @contextlib.contextmanager
def disabled(self): def disabled(self):
"""Temporarily disables capture while inside the 'with' block.""" """Context manager to temporarily disables capture."""
if self._current_item is None:
yield # 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: else:
item = self._current_item ctx_manager = self._dummy_context_manager()
fixture = getattr(item, "_capture_fixture", None)
if fixture is None: with ctx_manager:
self.suspend_global_capture(item=None, in_=False)
try:
yield yield
else: finally:
fixture._capture.suspend_capturing() self.resume_global_capture()
self.suspend_global_capture(item=None, in_=False)
try:
yield
finally:
self.resume_global_capture()
fixture._capture.resume_capturing()
def activate_fixture(self, item): def activate_fixture(self, item):
"""If the current item is using ``capsys`` or ``capfd``, activate them so they take precedence over """If the current item is using ``capsys`` or ``capfd``, activate them so they take precedence over
@ -340,12 +343,9 @@ class CaptureFixture(object):
def disabled(self): def disabled(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()
capmanager = self.request.config.pluginmanager.getplugin("capturemanager")
capmanager.suspend_global_capture(item=None, in_=False)
try: try:
yield yield
finally: finally:
capmanager.resume_global_capture()
self._capture.resume_capturing() self._capture.resume_capturing()