diff --git a/changelog/7224.breaking.rst b/changelog/7224.breaking.rst index 32ab2c073..32592695a 100644 --- a/changelog/7224.breaking.rst +++ b/changelog/7224.breaking.rst @@ -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. diff --git a/doc/en/deprecations.rst b/doc/en/deprecations.rst index fbcaf2ce4..0b7d3fecd 100644 --- a/doc/en/deprecations.rst +++ b/doc/en/deprecations.rst @@ -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). diff --git a/src/_pytest/deprecated.py b/src/_pytest/deprecated.py index 9f4570f85..f981a4a4b 100644 --- a/src/_pytest/deprecated.py +++ b/src/_pytest/deprecated.py @@ -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." diff --git a/src/_pytest/logging.py b/src/_pytest/logging.py index 39523d0a3..d875879a9 100644 --- a/src/_pytest/logging.py +++ b/src/_pytest/logging.py @@ -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,10 +614,8 @@ 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) + log = log_handler.stream.getvalue().strip() + item.add_report_section(when, "log", log) @pytest.hookimpl(hookwrapper=True) def pytest_runtest_setup(self, item): diff --git a/testing/deprecated_test.py b/testing/deprecated_test.py index edd5505c0..93264f3fc 100644 --- a/testing/deprecated_test.py +++ b/testing/deprecated_test.py @@ -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, diff --git a/testing/logging/test_reporting.py b/testing/logging/test_reporting.py index ad7af9370..c1335b180 100644 --- a/testing/logging/test_reporting.py +++ b/testing/logging/test_reporting.py @@ -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"