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.
This commit is contained in:
parent
51ece00923
commit
ac7eb63a6b
|
@ -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):
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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'
|
||||
|
|
Loading…
Reference in New Issue