From 14024c7fc13a1bb60c7971e418caec919a5276ee Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Mon, 3 Dec 2018 12:12:26 +0000 Subject: [PATCH] Test case for #4500 bug and respective fix #4487 --- testing/test_capture.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/testing/test_capture.py b/testing/test_capture.py index c113f0304..2e1912f2e 100644 --- a/testing/test_capture.py +++ b/testing/test_capture.py @@ -385,6 +385,35 @@ class TestLoggingInteraction(object): assert "something" not in result.stderr.str() assert "operation on closed file" not in result.stderr.str() + def test_logging_after_cap_stopped(self, testdir): + testdir.makeconftest( + """\ + import pytest + import logging + + log = logging.getLogger(__name__) + + @pytest.fixture + def log_on_teardown(): + yield + log.warning('Logging on teardown') + """ + ) + # make sure that logging is still captured in tests + p = testdir.makepyfile( + """\ + def test_hello(log_on_teardown): + import logging + logging.warning("hello433") + assert 1 + raise KeyboardInterrupt() + """ + ) + result = testdir.runpytest_subprocess(p, "--log-cli-level", "info") + assert result.ret != 0 + result.stdout.fnmatch_lines(["*WARNING*hello433*", "*WARNING*Logging on teardown*"]) + assert "AttributeError: 'NoneType' object has no attribute 'resume_capturing'" not in result.stderr.str() + class TestCaptureFixture(object): @pytest.mark.parametrize("opt", [[], ["-s"]])