From ac7eb63a6b9899250ebd58f61f348ef69bf55875 Mon Sep 17 00:00:00 2001 From: Thomas Hisch Date: Sun, 18 Feb 2018 20:48:07 +0100 Subject: [PATCH] Remove --no-print-logs option This option is superseded by the --show-capture option. With --no-print-logs it was possible to only disable the reporting of captured logs, which is no longer possible with --show-capture. If --show-capture=no is used, no captured content (stdout, stderr and logs) is reported for failed tests. --- _pytest/logging.py | 13 ++------ doc/en/logging.rst | 22 ++----------- testing/logging/test_reporting.py | 54 ------------------------------- 3 files changed, 6 insertions(+), 83 deletions(-) diff --git a/_pytest/logging.py b/_pytest/logging.py index d3ac81e65..b719f3a79 100644 --- a/_pytest/logging.py +++ b/_pytest/logging.py @@ -84,11 +84,6 @@ def pytest_addoption(parser): help='default value for ' + option) 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', default=None, @@ -343,7 +338,6 @@ class LoggingPlugin(object): assert self._config.pluginmanager.get_plugin('terminalreporter') is None config.option.verbose = 1 - self.print_logs = get_option_ini(config, 'log_print') self.formatter = logging.Formatter(get_option_ini(config, 'log_format'), get_option_ini(config, 'log_date_format')) self.log_level = get_actual_log_level(config, 'log_level') @@ -394,10 +388,9 @@ class LoggingPlugin(object): if when == 'teardown': del item.catch_log_handlers - 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) + # Add a captured log section to the report. + 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/doc/en/logging.rst b/doc/en/logging.rst index 82119043b..ad59be83f 100644 --- a/doc/en/logging.rst +++ b/doc/en/logging.rst @@ -50,26 +50,10 @@ These options can also be customized through ``pytest.ini`` file: log_format = %(asctime)s %(levelname)s %(message)s log_date_format = %Y-%m-%d %H:%M:%S -Further it is possible to disable reporting logs on failed tests completely -with:: +Further it is possible to disable reporting of captured content (stdout, +stderr and logs) on failed tests completely with:: - pytest --no-print-logs - -Or in the ``pytest.ini`` file: - -.. code-block:: ini - - [pytest] - log_print = False - - -Shows failed tests in the normal manner as no logs were captured:: - - ----------------------- Captured stdout call ---------------------- - text going to stdout - ----------------------- Captured stderr call ---------------------- - text going to stderr - ==================== 2 failed in 0.02 seconds ===================== + pytest --show-capture=no caplog fixture diff --git a/testing/logging/test_reporting.py b/testing/logging/test_reporting.py index f84f7e459..7f4c3f17d 100644 --- a/testing/logging/test_reporting.py +++ b/testing/logging/test_reporting.py @@ -91,60 +91,6 @@ def test_teardown_logging(testdir): '*text going to logger from teardown*']) -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'