diff --git a/changelog/3238.deprecation.rst b/changelog/3238.deprecation.rst new file mode 100644 index 000000000..e4e8f25ea --- /dev/null +++ b/changelog/3238.deprecation.rst @@ -0,0 +1,5 @@ +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. + +``--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/doc/en/deprecations.rst b/doc/en/deprecations.rst index 88112b12a..bb91b9a11 100644 --- a/doc/en/deprecations.rst +++ b/doc/en/deprecations.rst @@ -20,6 +20,20 @@ Below is a complete list of all pytest features which are considered deprecated. :ref:`standard warning filters `. +``--no-print-logs`` command-line option +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. deprecated:: 5.4 + + +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. + +``--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). + + + Node Construction changed to ``Node.from_parent`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/src/_pytest/deprecated.py b/src/_pytest/deprecated.py index 1fdc37c04..afaa0e72a 100644 --- a/src/_pytest/deprecated.py +++ b/src/_pytest/deprecated.py @@ -19,13 +19,11 @@ DEPRECATED_EXTERNAL_PLUGINS = { "pytest_faulthandler", } - FUNCARGNAMES = PytestDeprecationWarning( "The `funcargnames` attribute was an alias for `fixturenames`, " "since pytest 2.3 - use the newer attribute instead." ) - RESULT_LOG = PytestDeprecationWarning( "--result-log is deprecated, please try the new pytest-reportlog plugin.\n" "See https://docs.pytest.org/en/latest/deprecations.html#result-log-result-log for more information." @@ -45,3 +43,8 @@ JUNIT_XML_DEFAULT_FAMILY = PytestDeprecationWarning( "The 'junit_family' default value will change to 'xunit2' in pytest 6.0.\n" "Add 'junit_family=legacy' to your pytest.ini file to silence this warning and make your suite compatible." ) + +NO_PRINT_LOGS = PytestDeprecationWarning( + "--no-print-logs is deprecated and scheduled for removal in pytest 6.0.\n" + "Please use --show-capture instead." +) diff --git a/src/_pytest/logging.py b/src/_pytest/logging.py index ccd79b834..e4ccad2c3 100644 --- a/src/_pytest/logging.py +++ b/src/_pytest/logging.py @@ -485,6 +485,12 @@ 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) + self.formatter = self._create_formatter( get_option_ini(config, "log_format"), get_option_ini(config, "log_date_format"), diff --git a/testing/deprecated_test.py b/testing/deprecated_test.py index 59cb69a00..c7ca80cbd 100644 --- a/testing/deprecated_test.py +++ b/testing/deprecated_test.py @@ -90,3 +90,44 @@ def test_node_direct_ctor_warning(): nodes.Node(name="test", config=ms, session=ms, nodeid="None") assert w[0].lineno == inspect.currentframe().f_lineno - 1 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, ())