Skip to content

Commit 3f82006

Browse files
committed
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.
1 parent bd5e3f0 commit 3f82006

File tree

6 files changed

+6
-122
lines changed

6 files changed

+6
-122
lines changed

changelog/7224.breaking.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
The `item.catch_log_handler` and `item.catch_log_handlers` attributes, set by the
22
logging plugin and never meant to be public , are no longer available.
3+
4+
The deprecated ``--no-print-logs`` option is removed. Use ``--show-capture`` instead.

doc/en/deprecations.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ a public API and may break in the future.
3737
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3838

3939
.. deprecated:: 5.4
40+
.. versionremoved:: 6.0
4041

4142

42-
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
43-
provide feedback.
43+
Option ``--no-print-logs`` is removed. If you used ``--no-print-logs``, please use ``--show-capture`` instead.
4444

4545
``--show-capture`` command-line option was added in ``pytest 3.5.0`` and allows to specify how to
4646
display captured output when tests fail: ``no``, ``stdout``, ``stderr``, ``log`` or ``all`` (the default).

src/_pytest/deprecated.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,6 @@
5454
"for more information."
5555
)
5656

57-
NO_PRINT_LOGS = PytestDeprecationWarning(
58-
"--no-print-logs is deprecated and scheduled for removal in pytest 6.0.\n"
59-
"Please use --show-capture instead."
60-
)
61-
6257
COLLECT_DIRECTORY_HOOK = PytestDeprecationWarning(
6358
"The pytest_collect_directory hook is not working.\n"
6459
"Please use collect_ignore in conftests or pytest_collection_modifyitems."

src/_pytest/logging.py

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -190,15 +190,6 @@ def add_option_ini(option, dest, default=None, type=None, **kwargs):
190190
)
191191
group.addoption(option, dest=dest, **kwargs)
192192

193-
add_option_ini(
194-
"--no-print-logs",
195-
dest="log_print",
196-
action="store_const",
197-
const=False,
198-
default=True,
199-
type="bool",
200-
help="disable printing caught logs on failed tests.",
201-
)
202193
add_option_ini(
203194
"--log-level",
204195
dest="log_level",
@@ -499,13 +490,6 @@ def __init__(self, config: Config) -> None:
499490
"""
500491
self._config = config
501492

502-
self.print_logs = get_option_ini(config, "log_print")
503-
if not self.print_logs:
504-
from _pytest.warnings import _issue_warning_captured
505-
from _pytest.deprecated import NO_PRINT_LOGS
506-
507-
_issue_warning_captured(NO_PRINT_LOGS, self._config.hook, stacklevel=2)
508-
509493
# Report logging.
510494
self.formatter = self._create_formatter(
511495
get_option_ini(config, "log_format"),
@@ -630,10 +614,8 @@ def _runtest_for(self, item: nodes.Item, when: str) -> Generator[None, None, Non
630614

631615
yield
632616

633-
if self.print_logs:
634-
# Add a captured log section to the report.
635-
log = log_handler.stream.getvalue().strip()
636-
item.add_report_section(when, "log", log)
617+
log = log_handler.stream.getvalue().strip()
618+
item.add_report_section(when, "log", log)
637619

638620
@pytest.hookimpl(hookwrapper=True)
639621
def pytest_runtest_setup(self, item):

testing/deprecated_test.py

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -117,47 +117,6 @@ class MockConfig:
117117
assert w[0].filename == __file__
118118

119119

120-
def assert_no_print_logs(testdir, args):
121-
result = testdir.runpytest(*args)
122-
result.stdout.fnmatch_lines(
123-
[
124-
"*--no-print-logs is deprecated and scheduled for removal in pytest 6.0*",
125-
"*Please use --show-capture instead.*",
126-
]
127-
)
128-
129-
130-
@pytest.mark.filterwarnings("default")
131-
def test_noprintlogs_is_deprecated_cmdline(testdir):
132-
testdir.makepyfile(
133-
"""
134-
def test_foo():
135-
pass
136-
"""
137-
)
138-
139-
assert_no_print_logs(testdir, ("--no-print-logs",))
140-
141-
142-
@pytest.mark.filterwarnings("default")
143-
def test_noprintlogs_is_deprecated_ini(testdir):
144-
testdir.makeini(
145-
"""
146-
[pytest]
147-
log_print=False
148-
"""
149-
)
150-
151-
testdir.makepyfile(
152-
"""
153-
def test_foo():
154-
pass
155-
"""
156-
)
157-
158-
assert_no_print_logs(testdir, ())
159-
160-
161120
def test__fillfuncargs_is_deprecated() -> None:
162121
with pytest.warns(
163122
pytest.PytestDeprecationWarning,

testing/logging/test_reporting.py

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -166,60 +166,6 @@ def teardown_function(function):
166166
)
167167

168168

169-
def test_disable_log_capturing(testdir):
170-
testdir.makepyfile(
171-
"""
172-
import sys
173-
import logging
174-
175-
logger = logging.getLogger(__name__)
176-
177-
def test_foo():
178-
sys.stdout.write('text going to stdout')
179-
logger.warning('catch me if you can!')
180-
sys.stderr.write('text going to stderr')
181-
assert False
182-
"""
183-
)
184-
result = testdir.runpytest("--no-print-logs")
185-
print(result.stdout)
186-
assert result.ret == 1
187-
result.stdout.fnmatch_lines(["*- Captured stdout call -*", "text going to stdout"])
188-
result.stdout.fnmatch_lines(["*- Captured stderr call -*", "text going to stderr"])
189-
with pytest.raises(pytest.fail.Exception):
190-
result.stdout.fnmatch_lines(["*- Captured *log call -*"])
191-
192-
193-
def test_disable_log_capturing_ini(testdir):
194-
testdir.makeini(
195-
"""
196-
[pytest]
197-
log_print=False
198-
"""
199-
)
200-
testdir.makepyfile(
201-
"""
202-
import sys
203-
import logging
204-
205-
logger = logging.getLogger(__name__)
206-
207-
def test_foo():
208-
sys.stdout.write('text going to stdout')
209-
logger.warning('catch me if you can!')
210-
sys.stderr.write('text going to stderr')
211-
assert False
212-
"""
213-
)
214-
result = testdir.runpytest()
215-
print(result.stdout)
216-
assert result.ret == 1
217-
result.stdout.fnmatch_lines(["*- Captured stdout call -*", "text going to stdout"])
218-
result.stdout.fnmatch_lines(["*- Captured stderr call -*", "text going to stderr"])
219-
with pytest.raises(pytest.fail.Exception):
220-
result.stdout.fnmatch_lines(["*- Captured *log call -*"])
221-
222-
223169
@pytest.mark.parametrize("enabled", [True, False])
224170
def test_log_cli_enabled_disabled(testdir, enabled):
225171
msg = "critical message logged by test"

0 commit comments

Comments
 (0)