logging: remove deprecated --no-print-logs option/ini
This option was deprecated in 5.4.0 and was marked for removal in 6.0.0.
This commit is contained in:
parent
bd5e3f042d
commit
3f8200676f
|
@ -1,2 +1,4 @@
|
|||
The `item.catch_log_handler` and `item.catch_log_handlers` attributes, set by the
|
||||
logging plugin and never meant to be public , are no longer available.
|
||||
|
||||
The deprecated ``--no-print-logs`` option is removed. Use ``--show-capture`` instead.
|
||||
|
|
|
@ -37,10 +37,10 @@ a public API and may break in the future.
|
|||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
.. deprecated:: 5.4
|
||||
.. versionremoved:: 6.0
|
||||
|
||||
|
||||
Option ``--no-print-logs`` is deprecated and meant to be removed in a future release. If you use ``--no-print-logs``, please try out ``--show-capture`` and
|
||||
provide feedback.
|
||||
Option ``--no-print-logs`` is removed. If you used ``--no-print-logs``, please use ``--show-capture`` instead.
|
||||
|
||||
``--show-capture`` command-line option was added in ``pytest 3.5.0`` and allows to specify how to
|
||||
display captured output when tests fail: ``no``, ``stdout``, ``stderr``, ``log`` or ``all`` (the default).
|
||||
|
|
|
@ -54,11 +54,6 @@ JUNIT_XML_DEFAULT_FAMILY = PytestDeprecationWarning(
|
|||
"for more information."
|
||||
)
|
||||
|
||||
NO_PRINT_LOGS = PytestDeprecationWarning(
|
||||
"--no-print-logs is deprecated and scheduled for removal in pytest 6.0.\n"
|
||||
"Please use --show-capture instead."
|
||||
)
|
||||
|
||||
COLLECT_DIRECTORY_HOOK = PytestDeprecationWarning(
|
||||
"The pytest_collect_directory hook is not working.\n"
|
||||
"Please use collect_ignore in conftests or pytest_collection_modifyitems."
|
||||
|
|
|
@ -190,15 +190,6 @@ def pytest_addoption(parser):
|
|||
)
|
||||
group.addoption(option, dest=dest, **kwargs)
|
||||
|
||||
add_option_ini(
|
||||
"--no-print-logs",
|
||||
dest="log_print",
|
||||
action="store_const",
|
||||
const=False,
|
||||
default=True,
|
||||
type="bool",
|
||||
help="disable printing caught logs on failed tests.",
|
||||
)
|
||||
add_option_ini(
|
||||
"--log-level",
|
||||
dest="log_level",
|
||||
|
@ -499,13 +490,6 @@ class LoggingPlugin:
|
|||
"""
|
||||
self._config = config
|
||||
|
||||
self.print_logs = get_option_ini(config, "log_print")
|
||||
if not self.print_logs:
|
||||
from _pytest.warnings import _issue_warning_captured
|
||||
from _pytest.deprecated import NO_PRINT_LOGS
|
||||
|
||||
_issue_warning_captured(NO_PRINT_LOGS, self._config.hook, stacklevel=2)
|
||||
|
||||
# Report logging.
|
||||
self.formatter = self._create_formatter(
|
||||
get_option_ini(config, "log_format"),
|
||||
|
@ -630,8 +614,6 @@ class LoggingPlugin:
|
|||
|
||||
yield
|
||||
|
||||
if self.print_logs:
|
||||
# Add a captured log section to the report.
|
||||
log = log_handler.stream.getvalue().strip()
|
||||
item.add_report_section(when, "log", log)
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue