From e7eb7e799bdfbd9ec167cdd0684291216ef169a3 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 19 Sep 2018 12:31:00 +0200 Subject: [PATCH 1/2] logging: del item.catch_log_handler only in teardown Without this caplog.record_tuples etc is not available anymore when using `--pdb`. --- changelog/3998.bugfix.rst | 1 + src/_pytest/logging.py | 2 +- testing/test_pdb.py | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 changelog/3998.bugfix.rst diff --git a/changelog/3998.bugfix.rst b/changelog/3998.bugfix.rst new file mode 100644 index 00000000000..9bb0fb7ad01 --- /dev/null +++ b/changelog/3998.bugfix.rst @@ -0,0 +1 @@ +Fix caplog's catch_log_handler not being available with --pdb diff --git a/src/_pytest/logging.py b/src/_pytest/logging.py index c9c65c4c18d..2d0f54a6454 100644 --- a/src/_pytest/logging.py +++ b/src/_pytest/logging.py @@ -445,8 +445,8 @@ def _runtest_for(self, item, when): 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: diff --git a/testing/test_pdb.py b/testing/test_pdb.py index ed1c49a1acf..246f514b4a9 100644 --- a/testing/test_pdb.py +++ b/testing/test_pdb.py @@ -397,6 +397,24 @@ def test_1(capsys): 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( """ From d1fa8ae08e52d5dbe966258746791dfbfd568c0a Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Wed, 19 Sep 2018 12:52:10 -0300 Subject: [PATCH 2/2] Improve CHANGELOG entry --- changelog/3998.bugfix.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog/3998.bugfix.rst b/changelog/3998.bugfix.rst index 9bb0fb7ad01..e696f7087bd 100644 --- a/changelog/3998.bugfix.rst +++ b/changelog/3998.bugfix.rst @@ -1 +1 @@ -Fix caplog's catch_log_handler not being available with --pdb +Fix issue that prevented some caplog properties (for example ``record_tuples``) from being available when entering the debugger with ``--pdb``.