Test case for #4500 bug and respective fix #4487

This commit is contained in:
Pedro Algarvio 2018-12-03 12:12:26 +00:00
parent 517b8bc69e
commit 14024c7fc1
No known key found for this signature in database
GPG Key ID: BB36BF6584A298FF
1 changed files with 29 additions and 0 deletions

View File

@ -385,6 +385,35 @@ class TestLoggingInteraction(object):
assert "something" not in result.stderr.str() assert "something" not in result.stderr.str()
assert "operation on closed file" 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): class TestCaptureFixture(object):
@pytest.mark.parametrize("opt", [[], ["-s"]]) @pytest.mark.parametrize("opt", [[], ["-s"]])