Skip to content

Commit 7aff817

Browse files
authored
Merge pull request #3998 from blueyed/logging-del
logging: del item.catch_log_handler only in teardown
2 parents 27772f6 + d1fa8ae commit 7aff817

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

changelog/3998.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix issue that prevented some caplog properties (for example ``record_tuples``) from being available when entering the debugger with ``--pdb``.

src/_pytest/logging.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,8 +445,8 @@ def _runtest_for(self, item, when):
445445
try:
446446
yield # run test
447447
finally:
448-
del item.catch_log_handler
449448
if when == "teardown":
449+
del item.catch_log_handler
450450
del item.catch_log_handlers
451451

452452
if self.print_logs:

testing/test_pdb.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,24 @@ def test_1(capsys):
397397
child.read()
398398
self.flush(child)
399399

400+
def test_pdb_with_caplog_on_pdb_invocation(self, testdir):
401+
p1 = testdir.makepyfile(
402+
"""
403+
def test_1(capsys, caplog):
404+
import logging
405+
logging.getLogger(__name__).warning("some_warning")
406+
assert 0
407+
"""
408+
)
409+
child = testdir.spawn_pytest("--pdb %s" % str(p1))
410+
child.send("caplog.record_tuples\n")
411+
child.expect_exact(
412+
"[('test_pdb_with_caplog_on_pdb_invocation', 30, 'some_warning')]"
413+
)
414+
child.sendeof()
415+
child.read()
416+
self.flush(child)
417+
400418
def test_set_trace_capturing_afterwards(self, testdir):
401419
p1 = testdir.makepyfile(
402420
"""

0 commit comments

Comments
 (0)