Skip to content

Commit 5fe1fdf

Browse files
committed
terminal: default to fE with -r (reportchars)
Adds handling of `N` to reset `reportchars`, which can be used to get the old behavior (`-rN`), and also allows for an alternative to `--disable-warnings` (#5066), since `w` was included by default (without `--disable-warnings`). Fixes #6454
1 parent 2f0d0fb commit 5fe1fdf

File tree

4 files changed

+52
-18
lines changed

4 files changed

+52
-18
lines changed

changelog/6454.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Changed default for `-r` to `fE`, which displays failures and errors in the :ref:`short test summary <pytest.detailed_failed_tests_usage>`. `-rN` can be used to disable it (the old behavior).

doc/en/usage.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,11 @@ option you make sure a trace is shown.
169169
Detailed summary report
170170
-----------------------
171171

172-
173-
174172
The ``-r`` flag can be used to display a "short test summary info" at the end of the test session,
175173
making it easy in large test suites to get a clear picture of all failures, skips, xfails, etc.
176174

175+
It defaults to ``fE`` to list failures and errors.
176+
177177
Example:
178178

179179
.. code-block:: python
@@ -261,8 +261,12 @@ Here is the full list of available characters that can be used:
261261
- ``X`` - xpassed
262262
- ``p`` - passed
263263
- ``P`` - passed with output
264+
265+
Special characters for (de)selection of groups:
266+
264267
- ``a`` - all except ``pP``
265268
- ``A`` - all
269+
- ``N`` - none, this can be used to display nothing (since ``fE`` is the default)
266270

267271
More than one character can be used, so for example to only see failed and skipped tests, you can execute:
268272

src/_pytest/terminal.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333

3434
REPORT_COLLECTING_RESOLUTION = 0.5
3535

36+
_REPORTCHARS_DEFAULT = "fE"
37+
3638

3739
class MoreQuietAction(argparse.Action):
3840
"""
@@ -88,12 +90,13 @@ def pytest_addoption(parser):
8890
"-r",
8991
action="store",
9092
dest="reportchars",
91-
default="",
93+
default=_REPORTCHARS_DEFAULT,
9294
metavar="chars",
9395
help="show extra test summary info as specified by chars: (f)ailed, "
9496
"(E)rror, (s)kipped, (x)failed, (X)passed, "
9597
"(p)assed, (P)assed with output, (a)ll except passed (p/P), or (A)ll. "
96-
"(w)arnings are enabled by default (see --disable-warnings).",
98+
"(w)arnings are enabled by default (see --disable-warnings), "
99+
"'N' can be used to reset the list. (default: 'fE').",
97100
)
98101
group._addoption(
99102
"--disable-warnings",
@@ -169,7 +172,7 @@ def getreportopt(config: Config) -> str:
169172
reportopts = ""
170173
reportchars = config.option.reportchars
171174
if not config.option.disable_warnings and "w" not in reportchars:
172-
reportchars += "w"
175+
reportchars = "w" + reportchars
173176
elif config.option.disable_warnings and "w" in reportchars:
174177
reportchars = reportchars.replace("w", "")
175178
aliases = {"F", "S"}
@@ -181,7 +184,8 @@ def getreportopt(config: Config) -> str:
181184
reportopts = "sxXwEf"
182185
elif char == "A":
183186
reportopts = "PpsxXwEf"
184-
break
187+
elif char == "N":
188+
reportopts = ""
185189
elif char not in reportopts:
186190
reportopts += char
187191
return reportopts

testing/test_terminal.py

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -807,9 +807,9 @@ def test():
807807
def test_fail_extra_reporting(testdir, monkeypatch):
808808
monkeypatch.setenv("COLUMNS", "80")
809809
testdir.makepyfile("def test_this(): assert 0, 'this_failed' * 100")
810-
result = testdir.runpytest()
810+
result = testdir.runpytest("-rN")
811811
result.stdout.no_fnmatch_line("*short test summary*")
812-
result = testdir.runpytest("-rf")
812+
result = testdir.runpytest()
813813
result.stdout.fnmatch_lines(
814814
[
815815
"*test summary*",
@@ -918,38 +918,63 @@ def test_this(i):
918918

919919

920920
def test_getreportopt():
921+
from _pytest.terminal import _REPORTCHARS_DEFAULT
922+
921923
class Config:
922924
class Option:
923-
reportchars = ""
924-
disable_warnings = True
925+
reportchars = _REPORTCHARS_DEFAULT
926+
disable_warnings = False
925927

926928
option = Option()
927929

928930
config = Config()
929931

932+
assert _REPORTCHARS_DEFAULT == "fE"
933+
934+
# Default.
935+
assert getreportopt(config) == "wfE"
936+
930937
config.option.reportchars = "sf"
931-
assert getreportopt(config) == "sf"
938+
assert getreportopt(config) == "wsf"
932939

933940
config.option.reportchars = "sfxw"
934-
assert getreportopt(config) == "sfx"
941+
assert getreportopt(config) == "sfxw"
942+
943+
config.option.reportchars = "a"
944+
assert getreportopt(config) == "sxXwEf"
945+
946+
config.option.reportchars = "N"
947+
assert getreportopt(config) == ""
948+
949+
config.option.reportchars = "NwfE"
950+
assert getreportopt(config) == "wfE"
951+
952+
config.option.reportchars = "NfENx"
953+
assert getreportopt(config) == "x"
935954

936955
# Now with --disable-warnings.
937-
config.option.disable_warnings = False
956+
config.option.disable_warnings = True
938957
config.option.reportchars = "a"
939-
assert getreportopt(config) == "sxXwEf" # NOTE: "w" included!
958+
assert getreportopt(config) == "sxXwEf"
940959

941960
config.option.reportchars = "sfx"
942-
assert getreportopt(config) == "sfxw"
961+
assert getreportopt(config) == "sfx"
943962

944963
config.option.reportchars = "sfxw"
945-
assert getreportopt(config) == "sfxw"
964+
assert getreportopt(config) == "sfx"
946965

947966
config.option.reportchars = "a"
948-
assert getreportopt(config) == "sxXwEf" # NOTE: "w" included!
967+
assert getreportopt(config) == "sxXwEf"
949968

950969
config.option.reportchars = "A"
951970
assert getreportopt(config) == "PpsxXwEf"
952971

972+
config.option.reportchars = "AN"
973+
assert getreportopt(config) == ""
974+
975+
config.option.reportchars = "NwfE"
976+
assert getreportopt(config) == "fE"
977+
953978

954979
def test_terminalreporter_reportopt_addopts(testdir):
955980
testdir.makeini("[pytest]\naddopts=-rs")
@@ -1065,7 +1090,7 @@ def test_func():
10651090
)
10661091
for tbopt in ["long", "short", "no"]:
10671092
print("testing --tb=%s..." % tbopt)
1068-
result = testdir.runpytest("--tb=%s" % tbopt)
1093+
result = testdir.runpytest("-rN", "--tb=%s" % tbopt)
10691094
s = result.stdout.str()
10701095
if tbopt == "long":
10711096
assert "print(6*7)" in s

0 commit comments

Comments
 (0)