logging: del item.catch_log_handler only in teardown

Without this caplog.record_tuples etc is not available anymore when using
`--pdb`.
This commit is contained in:
Daniel Hahler 2018-09-19 12:31:00 +02:00
parent bb57186dd4
commit e7eb7e799b
3 changed files with 20 additions and 1 deletions

View File

@ -0,0 +1 @@
Fix caplog's catch_log_handler not being available with --pdb

View File

@ -445,8 +445,8 @@ class LoggingPlugin(object):
try:
yield # run test
finally:
del item.catch_log_handler
if when == "teardown":
del item.catch_log_handler
del item.catch_log_handlers
if self.print_logs:

View File

@ -397,6 +397,24 @@ class TestPDB(object):
child.read()
self.flush(child)
def test_pdb_with_caplog_on_pdb_invocation(self, testdir):
p1 = testdir.makepyfile(
"""
def test_1(capsys, caplog):
import logging
logging.getLogger(__name__).warning("some_warning")
assert 0
"""
)
child = testdir.spawn_pytest("--pdb %s" % str(p1))
child.send("caplog.record_tuples\n")
child.expect_exact(
"[('test_pdb_with_caplog_on_pdb_invocation', 30, 'some_warning')]"
)
child.sendeof()
child.read()
self.flush(child)
def test_set_trace_capturing_afterwards(self, testdir):
p1 = testdir.makepyfile(
"""