Merge pull request #7224 from bluetech/logging-simplifications
logging: some simplifications/cleanups
This commit is contained in:
@@ -117,47 +117,6 @@ def test_node_direct_ctor_warning():
|
||||
assert w[0].filename == __file__
|
||||
|
||||
|
||||
def assert_no_print_logs(testdir, args):
|
||||
result = testdir.runpytest(*args)
|
||||
result.stdout.fnmatch_lines(
|
||||
[
|
||||
"*--no-print-logs is deprecated and scheduled for removal in pytest 6.0*",
|
||||
"*Please use --show-capture instead.*",
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.filterwarnings("default")
|
||||
def test_noprintlogs_is_deprecated_cmdline(testdir):
|
||||
testdir.makepyfile(
|
||||
"""
|
||||
def test_foo():
|
||||
pass
|
||||
"""
|
||||
)
|
||||
|
||||
assert_no_print_logs(testdir, ("--no-print-logs",))
|
||||
|
||||
|
||||
@pytest.mark.filterwarnings("default")
|
||||
def test_noprintlogs_is_deprecated_ini(testdir):
|
||||
testdir.makeini(
|
||||
"""
|
||||
[pytest]
|
||||
log_print=False
|
||||
"""
|
||||
)
|
||||
|
||||
testdir.makepyfile(
|
||||
"""
|
||||
def test_foo():
|
||||
pass
|
||||
"""
|
||||
)
|
||||
|
||||
assert_no_print_logs(testdir, ())
|
||||
|
||||
|
||||
def test__fillfuncargs_is_deprecated() -> None:
|
||||
with pytest.warns(
|
||||
pytest.PytestDeprecationWarning,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import logging
|
||||
|
||||
import pytest
|
||||
from _pytest.logging import catch_log_handlers_key
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
sublogger = logging.getLogger(__name__ + ".baz")
|
||||
@@ -136,4 +137,4 @@ def test_caplog_captures_for_all_stages(caplog, logging_during_setup_and_teardow
|
||||
assert [x.message for x in caplog.get_records("setup")] == ["a_setup_log"]
|
||||
|
||||
# This reaches into private API, don't use this type of thing in real tests!
|
||||
assert set(caplog._item.catch_log_handlers.keys()) == {"setup", "call"}
|
||||
assert set(caplog._item._store[catch_log_handlers_key]) == {"setup", "call"}
|
||||
|
||||
@@ -166,60 +166,6 @@ def test_teardown_logging(testdir):
|
||||
)
|
||||
|
||||
|
||||
def test_disable_log_capturing(testdir):
|
||||
testdir.makepyfile(
|
||||
"""
|
||||
import sys
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def test_foo():
|
||||
sys.stdout.write('text going to stdout')
|
||||
logger.warning('catch me if you can!')
|
||||
sys.stderr.write('text going to stderr')
|
||||
assert False
|
||||
"""
|
||||
)
|
||||
result = testdir.runpytest("--no-print-logs")
|
||||
print(result.stdout)
|
||||
assert result.ret == 1
|
||||
result.stdout.fnmatch_lines(["*- Captured stdout call -*", "text going to stdout"])
|
||||
result.stdout.fnmatch_lines(["*- Captured stderr call -*", "text going to stderr"])
|
||||
with pytest.raises(pytest.fail.Exception):
|
||||
result.stdout.fnmatch_lines(["*- Captured *log call -*"])
|
||||
|
||||
|
||||
def test_disable_log_capturing_ini(testdir):
|
||||
testdir.makeini(
|
||||
"""
|
||||
[pytest]
|
||||
log_print=False
|
||||
"""
|
||||
)
|
||||
testdir.makepyfile(
|
||||
"""
|
||||
import sys
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def test_foo():
|
||||
sys.stdout.write('text going to stdout')
|
||||
logger.warning('catch me if you can!')
|
||||
sys.stderr.write('text going to stderr')
|
||||
assert False
|
||||
"""
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
print(result.stdout)
|
||||
assert result.ret == 1
|
||||
result.stdout.fnmatch_lines(["*- Captured stdout call -*", "text going to stdout"])
|
||||
result.stdout.fnmatch_lines(["*- Captured stderr call -*", "text going to stderr"])
|
||||
with pytest.raises(pytest.fail.Exception):
|
||||
result.stdout.fnmatch_lines(["*- Captured *log call -*"])
|
||||
|
||||
|
||||
@pytest.mark.parametrize("enabled", [True, False])
|
||||
def test_log_cli_enabled_disabled(testdir, enabled):
|
||||
msg = "critical message logged by test"
|
||||
|
||||
Reference in New Issue
Block a user