From 0ddb0296b3cf94eba581b201db085dec06d0577c Mon Sep 17 00:00:00 2001 From: Brian Maissy Date: Sun, 18 Feb 2018 23:24:59 +0200 Subject: [PATCH] dont print logs when --no-print-logs is defined, test when logging plugins is disabled --- _pytest/debugging.py | 5 +++-- testing/test_pdb.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/_pytest/debugging.py b/_pytest/debugging.py index d74cbe186ae..fd7ee23fc32 100644 --- a/_pytest/debugging.py +++ b/_pytest/debugging.py @@ -99,8 +99,9 @@ def _enter_pdb(node, excinfo, rep): captured_logs = rep.caplog if len(captured_logs) > 0: - tw.sep(">", "captured logs") - tw.line(captured_logs) + if node.config.getoption('log_print') is not False: + tw.sep(">", "captured logs") + tw.line(captured_logs) tw.sep(">", "traceback") rep.toterminal(tw) diff --git a/testing/test_pdb.py b/testing/test_pdb.py index f6d03d6bb7f..6be17885bbf 100644 --- a/testing/test_pdb.py +++ b/testing/test_pdb.py @@ -203,6 +203,40 @@ def test_1(): assert "1 failed" in rest self.flush(child) + def test_pdb_dont_print_captured_logs_when_no_print_logs_is_defined(self, testdir): + p1 = testdir.makepyfile(""" + def test_1(): + import logging + logging.warn("get rekt") + assert False + """) + child = testdir.spawn_pytest("--pdb --no-print-logs %s" % p1) + child.expect("get rekt") + output = child.before.decode("utf8") + assert "captured logs" not in output + child.expect("(Pdb)") + child.sendeof() + rest = child.read().decode("utf8") + assert "1 failed" in rest + self.flush(child) + + def test_pdb_doesnt_print_captured_logs_when_logging_plugin_is_disabled(self, testdir): + p1 = testdir.makepyfile(""" + def test_1(): + import logging + logging.warn("get rekt") + assert False + """) + child = testdir.spawn_pytest("--pdb -p no:logging %s" % p1) + child.expect("get rekt") + output = child.before.decode("utf8") + assert "captured logs" not in output + child.expect("(Pdb)") + child.sendeof() + rest = child.read().decode("utf8") + assert "1 failed" in rest + self.flush(child) + def test_pdb_interaction_exception(self, testdir): p1 = testdir.makepyfile(""" import pytest