Skip to content

Commit

Permalink
dont print logs when --no-print-logs is defined, test when logging pl…
Browse files Browse the repository at this point in the history
…ugins is disabled
  • Loading branch information
brianmaissy committed Feb 18, 2018
1 parent 9d8699d commit 0ddb029
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
5 changes: 3 additions & 2 deletions _pytest/debugging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
34 changes: 34 additions & 0 deletions testing/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0ddb029

Please sign in to comment.