From da9d814da43a32f9eb3924e5b5618a80d7786731 Mon Sep 17 00:00:00 2001 From: Victor Date: Fri, 17 Aug 2018 00:20:51 +0200 Subject: [PATCH 01/12] Added test. --- testing/test_capture.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/testing/test_capture.py b/testing/test_capture.py index 5f5e1b98d..9140d2fbf 100644 --- a/testing/test_capture.py +++ b/testing/test_capture.py @@ -1385,3 +1385,31 @@ def test_pickling_and_unpickling_encoded_file(): ef = capture.EncodedFile(None, None) ef_as_str = pickle.dumps(ef) pickle.loads(ef_as_str) + + +def test_capsys_with_cli_logging(testdir): + # Issue 3819 + # capsys should work with real-time cli logging + testdir.makepyfile( + """ + import logging + import sys + + logger = logging.getLogger(__name__) + + def test_myoutput(capsys): # or use "capfd" for fd-level + print("hello") + sys.stderr.write("world\\n") + captured = capsys.readouterr() + assert captured.out == "hello\\n" + assert captured.err == "world\\n" + + logging.info("something") + + print("next") + captured = capsys.readouterr() + assert captured.out == "next\\n" + """ + ) + result = testdir.runpytest_subprocess("--log-cli-level=INFO") + assert result.ret == 0 From 2b71cb9c381effaea13fa00c096a8f4c76a663b5 Mon Sep 17 00:00:00 2001 From: Victor Date: Fri, 17 Aug 2018 00:26:12 +0200 Subject: [PATCH 02/12] Added activation/deactivation of capture fixture in logging emit. --- src/_pytest/capture.py | 16 ++++++++++++++-- src/_pytest/logging.py | 2 ++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/_pytest/capture.py b/src/_pytest/capture.py index faa767a86..34d42821f 100644 --- a/src/_pytest/capture.py +++ b/src/_pytest/capture.py @@ -85,6 +85,7 @@ class CaptureManager(object): def __init__(self, method): self._method = method self._global_capturing = None + self._current_item = None def _getcapture(self, method): if method == "fd": @@ -121,15 +122,23 @@ class CaptureManager(object): cap.suspend_capturing(in_=in_) return outerr - def activate_fixture(self, item): + def activate_fixture(self, item=None): """If the current item is using ``capsys`` or ``capfd``, activate them so they take precedence over the global capture. """ + if item is None: + if self._current_item is None: + return + item = self._current_item fixture = getattr(item, "_capture_fixture", None) if fixture is not None: fixture._start() - def deactivate_fixture(self, item): + def deactivate_fixture(self, item=None): + if item is None: + if self._current_item is None: + return + item = self._current_item """Deactivates the ``capsys`` or ``capfd`` fixture of this item, if any.""" fixture = getattr(item, "_capture_fixture", None) if fixture is not None: @@ -151,6 +160,7 @@ class CaptureManager(object): @pytest.hookimpl(hookwrapper=True) def pytest_runtest_setup(self, item): + self._current_item = item self.resume_global_capture() # no need to activate a capture fixture because they activate themselves during creation; this # only makes sense when a fixture uses a capture fixture, otherwise the capture fixture will @@ -160,6 +170,7 @@ class CaptureManager(object): @pytest.hookimpl(hookwrapper=True) def pytest_runtest_call(self, item): + self._current_item = item self.resume_global_capture() # it is important to activate this fixture during the call phase so it overwrites the "global" # capture @@ -169,6 +180,7 @@ class CaptureManager(object): @pytest.hookimpl(hookwrapper=True) def pytest_runtest_teardown(self, item): + self._current_item = item self.resume_global_capture() self.activate_fixture(item) yield diff --git a/src/_pytest/logging.py b/src/_pytest/logging.py index 1472b0dbd..65ac2d24b 100644 --- a/src/_pytest/logging.py +++ b/src/_pytest/logging.py @@ -573,6 +573,7 @@ class _LiveLoggingStreamHandler(logging.StreamHandler): def emit(self, record): if self.capture_manager is not None: + self.capture_manager.deactivate_fixture() self.capture_manager.suspend_global_capture() try: if not self._first_record_emitted: @@ -589,3 +590,4 @@ class _LiveLoggingStreamHandler(logging.StreamHandler): finally: if self.capture_manager is not None: self.capture_manager.resume_global_capture() + self.capture_manager.activate_fixture() From f66764e1c00624b91c3ab9554c7872f9611ebc42 Mon Sep 17 00:00:00 2001 From: Victor Date: Fri, 17 Aug 2018 00:33:56 +0200 Subject: [PATCH 03/12] Added changelog and updated AUTHORS. --- AUTHORS | 1 + changelog/3819.bugfix.rst | 1 + 2 files changed, 2 insertions(+) create mode 100644 changelog/3819.bugfix.rst diff --git a/AUTHORS b/AUTHORS index 4a322b0a5..9c3cb6a12 100644 --- a/AUTHORS +++ b/AUTHORS @@ -206,6 +206,7 @@ Trevor Bekolay Tyler Goodlet Tzu-ping Chung Vasily Kuznetsov +Victor Maryama Victor Uriarte Vidar T. Fauske Vitaly Lashmanov diff --git a/changelog/3819.bugfix.rst b/changelog/3819.bugfix.rst new file mode 100644 index 000000000..02b33f9b1 --- /dev/null +++ b/changelog/3819.bugfix.rst @@ -0,0 +1 @@ +Fix ``stdout/stderr`` not getting captured when real-time cli logging is active. From e391c47ed8e6b4e68ec6e97b2ea3195a198e218f Mon Sep 17 00:00:00 2001 From: Victor Date: Fri, 17 Aug 2018 00:44:15 +0200 Subject: [PATCH 04/12] Update capture suspend test for logging. --- testing/logging/test_reporting.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/testing/logging/test_reporting.py b/testing/logging/test_reporting.py index 07c092191..a85a0aba0 100644 --- a/testing/logging/test_reporting.py +++ b/testing/logging/test_reporting.py @@ -889,6 +889,12 @@ def test_live_logging_suspends_capture(has_capture_manager, request): def resume_global_capture(self): self.calls.append("resume_global_capture") + def activate_fixture(self, item=None): + self.calls.append("activate_fixture") + + def deactivate_fixture(self, item=None): + self.calls.append("deactivate_fixture") + # sanity check assert CaptureManager.suspend_capture_item assert CaptureManager.resume_global_capture @@ -909,8 +915,10 @@ def test_live_logging_suspends_capture(has_capture_manager, request): logger.critical("some message") if has_capture_manager: assert MockCaptureManager.calls == [ + "deactivate_fixture", "suspend_global_capture", "resume_global_capture", + "activate_fixture", ] else: assert MockCaptureManager.calls == [] From 3059bfb1b3a45ab517da945acf74fe20abcad5a4 Mon Sep 17 00:00:00 2001 From: Victor Date: Fri, 17 Aug 2018 13:00:27 +0200 Subject: [PATCH 05/12] Update test with another problem. --- testing/test_capture.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/testing/test_capture.py b/testing/test_capture.py index 9140d2fbf..782971af0 100644 --- a/testing/test_capture.py +++ b/testing/test_capture.py @@ -1407,6 +1407,9 @@ def test_capsys_with_cli_logging(testdir): logging.info("something") print("next") + + logging.info("something") + captured = capsys.readouterr() assert captured.out == "next\\n" """ From 090f67a980adb7460d8600b6e49f7719c7c6e870 Mon Sep 17 00:00:00 2001 From: Victor Date: Fri, 17 Aug 2018 13:41:26 +0200 Subject: [PATCH 06/12] Refactored implementation and updated tests. --- src/_pytest/capture.py | 31 +++++++++++++++++++++---------- src/_pytest/logging.py | 12 +++++------- testing/logging/test_reporting.py | 24 +++++++----------------- 3 files changed, 33 insertions(+), 34 deletions(-) diff --git a/src/_pytest/capture.py b/src/_pytest/capture.py index 34d42821f..e6392cb0e 100644 --- a/src/_pytest/capture.py +++ b/src/_pytest/capture.py @@ -122,23 +122,34 @@ class CaptureManager(object): cap.suspend_capturing(in_=in_) return outerr - def activate_fixture(self, item=None): + @contextlib.contextmanager + def disabled(self): + """Temporarily disables capture while inside the 'with' block.""" + if self._current_item is None: + yield + else: + item = self._current_item + fixture = getattr(item, "_capture_fixture", None) + if fixture is None: + yield + else: + fixture._capture.suspend_capturing() + self.suspend_global_capture(item=None, in_=False) + try: + yield + finally: + self.resume_global_capture() + fixture._capture.resume_capturing() + + def activate_fixture(self, item): """If the current item is using ``capsys`` or ``capfd``, activate them so they take precedence over the global capture. """ - if item is None: - if self._current_item is None: - return - item = self._current_item fixture = getattr(item, "_capture_fixture", None) if fixture is not None: fixture._start() - def deactivate_fixture(self, item=None): - if item is None: - if self._current_item is None: - return - item = self._current_item + def deactivate_fixture(self, item): """Deactivates the ``capsys`` or ``capfd`` fixture of this item, if any.""" fixture = getattr(item, "_capture_fixture", None) if fixture is not None: diff --git a/src/_pytest/logging.py b/src/_pytest/logging.py index 65ac2d24b..ad049f1c5 100644 --- a/src/_pytest/logging.py +++ b/src/_pytest/logging.py @@ -573,9 +573,11 @@ class _LiveLoggingStreamHandler(logging.StreamHandler): def emit(self, record): if self.capture_manager is not None: - self.capture_manager.deactivate_fixture() - self.capture_manager.suspend_global_capture() - try: + ctx_manager = self.capture_manager.disabled() + else: + ctx_manager = _dummy_context_manager() + + with ctx_manager: if not self._first_record_emitted: self.stream.write("\n") self._first_record_emitted = True @@ -587,7 +589,3 @@ class _LiveLoggingStreamHandler(logging.StreamHandler): self.stream.section("live log " + self._when, sep="-", bold=True) self._section_name_shown = True logging.StreamHandler.emit(self, record) - finally: - if self.capture_manager is not None: - self.capture_manager.resume_global_capture() - self.capture_manager.activate_fixture() diff --git a/testing/logging/test_reporting.py b/testing/logging/test_reporting.py index a85a0aba0..ed89f5b7a 100644 --- a/testing/logging/test_reporting.py +++ b/testing/logging/test_reporting.py @@ -876,6 +876,7 @@ def test_live_logging_suspends_capture(has_capture_manager, request): is installed. """ import logging + import contextlib from functools import partial from _pytest.capture import CaptureManager from _pytest.logging import _LiveLoggingStreamHandler @@ -883,17 +884,11 @@ def test_live_logging_suspends_capture(has_capture_manager, request): class MockCaptureManager: calls = [] - def suspend_global_capture(self): - self.calls.append("suspend_global_capture") - - def resume_global_capture(self): - self.calls.append("resume_global_capture") - - def activate_fixture(self, item=None): - self.calls.append("activate_fixture") - - def deactivate_fixture(self, item=None): - self.calls.append("deactivate_fixture") + @contextlib.contextmanager + def disabled(self): + self.calls.append("enter disabled") + yield + self.calls.append("exit disabled") # sanity check assert CaptureManager.suspend_capture_item @@ -914,12 +909,7 @@ def test_live_logging_suspends_capture(has_capture_manager, request): logger.critical("some message") if has_capture_manager: - assert MockCaptureManager.calls == [ - "deactivate_fixture", - "suspend_global_capture", - "resume_global_capture", - "activate_fixture", - ] + assert MockCaptureManager.calls == ["enter disabled", "exit disabled"] else: assert MockCaptureManager.calls == [] assert out_file.getvalue() == "\nsome message\n" From 14db2f91ba5e94ebf55c55000b0da1e3b755cc26 Mon Sep 17 00:00:00 2001 From: victor Date: Sat, 18 Aug 2018 12:16:47 +0200 Subject: [PATCH 07/12] Fixed global not called if no capsys fixture. Using now capsys context manager as well. --- src/_pytest/capture.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/_pytest/capture.py b/src/_pytest/capture.py index e6392cb0e..9e017a733 100644 --- a/src/_pytest/capture.py +++ b/src/_pytest/capture.py @@ -121,25 +121,28 @@ class CaptureManager(object): finally: cap.suspend_capturing(in_=in_) return outerr + + @contextlib.contextmanager + def _dummy_context_manager(self): + yield @contextlib.contextmanager def disabled(self): - """Temporarily disables capture while inside the 'with' block.""" - if self._current_item is None: - yield + """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: - item = self._current_item - fixture = getattr(item, "_capture_fixture", None) - if fixture is None: + ctx_manager = self._dummy_context_manager() + + with ctx_manager: + self.suspend_global_capture(item=None, in_=False) + try: yield - else: - fixture._capture.suspend_capturing() - self.suspend_global_capture(item=None, in_=False) - try: - yield - finally: - self.resume_global_capture() - fixture._capture.resume_capturing() + finally: + self.resume_global_capture() def activate_fixture(self, item): """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): """Temporarily disables capture while inside the 'with' block.""" self._capture.suspend_capturing() - capmanager = self.request.config.pluginmanager.getplugin("capturemanager") - capmanager.suspend_global_capture(item=None, in_=False) try: yield finally: - capmanager.resume_global_capture() self._capture.resume_capturing() From 9fa7745795afd20e116cdd8ae93211a32054697b Mon Sep 17 00:00:00 2001 From: victor Date: Sat, 18 Aug 2018 13:40:08 +0200 Subject: [PATCH 08/12] Refactor, tests passing. --- src/_pytest/capture.py | 15 ++++++++------- src/_pytest/logging.py | 6 +----- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/_pytest/capture.py b/src/_pytest/capture.py index 9e017a733..323c91743 100644 --- a/src/_pytest/capture.py +++ b/src/_pytest/capture.py @@ -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 diff --git a/src/_pytest/logging.py b/src/_pytest/logging.py index ad049f1c5..fc40fc8b4 100644 --- a/src/_pytest/logging.py +++ b/src/_pytest/logging.py @@ -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") From eb2d0745301d597b7ef03450bea29c509237d60a Mon Sep 17 00:00:00 2001 From: victor Date: Sat, 18 Aug 2018 14:27:09 +0200 Subject: [PATCH 09/12] Black changes. --- src/_pytest/capture.py | 2 +- src/_pytest/logging.py | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/_pytest/capture.py b/src/_pytest/capture.py index 323c91743..606f7bdd9 100644 --- a/src/_pytest/capture.py +++ b/src/_pytest/capture.py @@ -121,7 +121,7 @@ class CaptureManager(object): finally: cap.suspend_capturing(in_=in_) return outerr - + @contextlib.contextmanager def _dummy_context_manager(self): yield diff --git a/src/_pytest/logging.py b/src/_pytest/logging.py index fc40fc8b4..395dc19e9 100644 --- a/src/_pytest/logging.py +++ b/src/_pytest/logging.py @@ -572,7 +572,11 @@ class _LiveLoggingStreamHandler(logging.StreamHandler): self._test_outcome_written = False def emit(self, record): - ctx_manager = self.capture_manager.disabled() if self.capture_manager else _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") From 9f7345d6639f803330835febee2694ceb925e08a Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Sat, 18 Aug 2018 11:08:03 -0300 Subject: [PATCH 10/12] Avoid leaving a reference to the last item on CaptureManager --- src/_pytest/capture.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/_pytest/capture.py b/src/_pytest/capture.py index 606f7bdd9..bd0fb87f0 100644 --- a/src/_pytest/capture.py +++ b/src/_pytest/capture.py @@ -176,6 +176,7 @@ class CaptureManager(object): # be activated during pytest_runtest_call yield self.suspend_capture_item(item, "setup") + self._current_item = None @pytest.hookimpl(hookwrapper=True) def pytest_runtest_call(self, item): @@ -186,6 +187,7 @@ class CaptureManager(object): self.activate_fixture(item) yield self.suspend_capture_item(item, "call") + self._current_item = None @pytest.hookimpl(hookwrapper=True) def pytest_runtest_teardown(self, item): @@ -194,6 +196,7 @@ class CaptureManager(object): self.activate_fixture(item) yield self.suspend_capture_item(item, "teardown") + self._current_item = None @pytest.hookimpl(tryfirst=True) def pytest_keyboard_interrupt(self, excinfo): From f674217c43c21f17b3693ce8b7b0e5bd06de2197 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Sat, 18 Aug 2018 11:15:58 -0300 Subject: [PATCH 11/12] Moved dummy_context_manager to compat module --- src/_pytest/capture.py | 9 ++------- src/_pytest/compat.py | 8 ++++++++ src/_pytest/logging.py | 10 +++------- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/_pytest/capture.py b/src/_pytest/capture.py index bd0fb87f0..4bf979efc 100644 --- a/src/_pytest/capture.py +++ b/src/_pytest/capture.py @@ -14,8 +14,7 @@ from tempfile import TemporaryFile import six import pytest -from _pytest.compat import CaptureIO - +from _pytest.compat import CaptureIO, dummy_context_manager patchsysdict = {0: "stdin", 1: "stdout", 2: "stderr"} @@ -122,16 +121,12 @@ class CaptureManager(object): cap.suspend_capturing(in_=in_) return outerr - @contextlib.contextmanager - def _dummy_context_manager(self): - yield - @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) - ctx_manager = fixture.suspend() if fixture else self._dummy_context_manager() + ctx_manager = fixture.suspend() if fixture else dummy_context_manager() with ctx_manager: self.suspend_global_capture(item=None, in_=False) try: diff --git a/src/_pytest/compat.py b/src/_pytest/compat.py index c3ecaf912..ea369ccf2 100644 --- a/src/_pytest/compat.py +++ b/src/_pytest/compat.py @@ -8,6 +8,7 @@ import functools import inspect import re import sys +from contextlib import contextmanager import py @@ -151,6 +152,13 @@ def getfuncargnames(function, is_method=False, cls=None): return arg_names +@contextmanager +def dummy_context_manager(): + """Context manager that does nothing, useful in situations where you might need an actual context manager or not + depending on some condition. Using this allow to keep the same code""" + yield + + def get_default_arg_names(function): # Note: this code intentionally mirrors the code at the beginning of getfuncargnames, # to get the arguments which were excluded from its result because they had default values diff --git a/src/_pytest/logging.py b/src/_pytest/logging.py index 395dc19e9..5b0fcd693 100644 --- a/src/_pytest/logging.py +++ b/src/_pytest/logging.py @@ -6,6 +6,7 @@ from contextlib import closing, contextmanager import re import six +from _pytest.compat import dummy_context_manager from _pytest.config import create_terminal_writer import pytest import py @@ -369,11 +370,6 @@ def pytest_configure(config): config.pluginmanager.register(LoggingPlugin(config), "logging-plugin") -@contextmanager -def _dummy_context_manager(): - yield - - class LoggingPlugin(object): """Attaches to the logging module and captures log messages for each test. """ @@ -537,7 +533,7 @@ class LoggingPlugin(object): log_cli_handler, formatter=log_cli_formatter, level=log_cli_level ) else: - self.live_logs_context = _dummy_context_manager() + self.live_logs_context = dummy_context_manager() class _LiveLoggingStreamHandler(logging.StreamHandler): @@ -575,7 +571,7 @@ class _LiveLoggingStreamHandler(logging.StreamHandler): ctx_manager = ( self.capture_manager.disabled() if self.capture_manager - else _dummy_context_manager() + else dummy_context_manager() ) with ctx_manager: if not self._first_record_emitted: From 5cf7d1dba21b51d4d20dc61b5a2f50bf5fc4fbf0 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Sat, 18 Aug 2018 11:36:24 -0300 Subject: [PATCH 12/12] "suspend" method of capture fixture private Also change the context-manager to global_and_fixture_disabled to better convey its meaning --- src/_pytest/capture.py | 13 +++++++------ src/_pytest/logging.py | 2 +- testing/logging/test_reporting.py | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/_pytest/capture.py b/src/_pytest/capture.py index 4bf979efc..c84ba825e 100644 --- a/src/_pytest/capture.py +++ b/src/_pytest/capture.py @@ -122,11 +122,11 @@ class CaptureManager(object): return outerr @contextlib.contextmanager - def disabled(self): - """Context manager to temporarily disables capture.""" + def global_and_fixture_disabled(self): + """Context manager to temporarily disables global and current fixture capturing.""" # Need to undo local capsys-et-al if exists before disabling global capture 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: self.suspend_global_capture(item=None, in_=False) try: @@ -333,8 +333,8 @@ class CaptureFixture(object): return self._outerr @contextlib.contextmanager - def suspend(self): - """Temporarily disables capture while inside the 'with' block.""" + def _suspend(self): + """Suspends this fixture's own capturing temporarily.""" self._capture.suspend_capturing() try: yield @@ -343,8 +343,9 @@ class CaptureFixture(object): @contextlib.contextmanager def disabled(self): + """Temporarily disables capture while inside the 'with' block.""" capmanager = self.request.config.pluginmanager.getplugin("capturemanager") - with capmanager.disabled(): + with capmanager.global_and_fixture_disabled(): yield diff --git a/src/_pytest/logging.py b/src/_pytest/logging.py index 5b0fcd693..c9c65c4c1 100644 --- a/src/_pytest/logging.py +++ b/src/_pytest/logging.py @@ -569,7 +569,7 @@ class _LiveLoggingStreamHandler(logging.StreamHandler): def emit(self, record): ctx_manager = ( - self.capture_manager.disabled() + self.capture_manager.global_and_fixture_disabled() if self.capture_manager else dummy_context_manager() ) diff --git a/testing/logging/test_reporting.py b/testing/logging/test_reporting.py index ed89f5b7a..820295886 100644 --- a/testing/logging/test_reporting.py +++ b/testing/logging/test_reporting.py @@ -885,7 +885,7 @@ def test_live_logging_suspends_capture(has_capture_manager, request): calls = [] @contextlib.contextmanager - def disabled(self): + def global_and_fixture_disabled(self): self.calls.append("enter disabled") yield self.calls.append("exit disabled")