Skip to content

Commit 2973ce1

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 2e8f7ef commit 2973ce1

File tree

4 files changed

+64
-28
lines changed

4 files changed

+64
-28
lines changed

changelog/6454.feature.rst

+1
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

+6-2
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

+19-13
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",
@@ -166,24 +169,27 @@ def mywriter(tags, args):
166169

167170

168171
def getreportopt(config: Config) -> str:
169-
reportopts = ""
170172
reportchars = config.option.reportchars
171-
if not config.option.disable_warnings and "w" not in reportchars:
172-
reportchars += "w"
173-
elif config.option.disable_warnings and "w" in reportchars:
174-
reportchars = reportchars.replace("w", "")
175-
aliases = {"F", "S"}
173+
174+
old_aliases = {"F", "S"}
175+
reportopts = ""
176176
for char in reportchars:
177-
# handle old aliases
178-
if char in aliases:
177+
if char in old_aliases:
179178
char = char.lower()
180179
if char == "a":
181-
reportopts = "sxXwEf"
180+
reportopts = "sxXEf"
182181
elif char == "A":
183-
reportopts = "PpsxXwEf"
184-
break
182+
reportopts = "PpsxXEf"
183+
elif char == "N":
184+
reportopts = ""
185185
elif char not in reportopts:
186186
reportopts += char
187+
188+
if not config.option.disable_warnings and "w" not in reportopts:
189+
reportopts = "w" + reportopts
190+
elif config.option.disable_warnings and "w" in reportopts:
191+
reportopts = reportopts.replace("w", "")
192+
187193
return reportopts
188194

189195

testing/test_terminal.py

+38-13
Original file line numberDiff line numberDiff line change
@@ -813,9 +813,9 @@ def test():
813813
def test_fail_extra_reporting(testdir, monkeypatch):
814814
monkeypatch.setenv("COLUMNS", "80")
815815
testdir.makepyfile("def test_this(): assert 0, 'this_failed' * 100")
816-
result = testdir.runpytest()
816+
result = testdir.runpytest("-rN")
817817
result.stdout.no_fnmatch_line("*short test summary*")
818-
result = testdir.runpytest("-rf")
818+
result = testdir.runpytest()
819819
result.stdout.fnmatch_lines(
820820
[
821821
"*test summary*",
@@ -984,37 +984,62 @@ def test_this(i):
984984

985985

986986
def test_getreportopt():
987+
from _pytest.terminal import _REPORTCHARS_DEFAULT
988+
987989
class Config:
988990
class Option:
989-
reportchars = ""
990-
disable_warnings = True
991+
reportchars = _REPORTCHARS_DEFAULT
992+
disable_warnings = False
991993

992994
option = Option()
993995

994996
config = Config()
995997

998+
assert _REPORTCHARS_DEFAULT == "fE"
999+
1000+
# Default.
1001+
assert getreportopt(config) == "wfE"
1002+
9961003
config.option.reportchars = "sf"
997-
assert getreportopt(config) == "sf"
1004+
assert getreportopt(config) == "wsf"
9981005

9991006
config.option.reportchars = "sfxw"
1000-
assert getreportopt(config) == "sfx"
1007+
assert getreportopt(config) == "sfxw"
1008+
1009+
config.option.reportchars = "a"
1010+
assert getreportopt(config) == "wsxXEf"
1011+
1012+
config.option.reportchars = "N"
1013+
assert getreportopt(config) == "w"
1014+
1015+
config.option.reportchars = "NwfE"
1016+
assert getreportopt(config) == "wfE"
1017+
1018+
config.option.reportchars = "NfENx"
1019+
assert getreportopt(config) == "wx"
10011020

10021021
# Now with --disable-warnings.
1003-
config.option.disable_warnings = False
1022+
config.option.disable_warnings = True
10041023
config.option.reportchars = "a"
1005-
assert getreportopt(config) == "sxXwEf" # NOTE: "w" included!
1024+
assert getreportopt(config) == "sxXEf"
10061025

10071026
config.option.reportchars = "sfx"
1008-
assert getreportopt(config) == "sfxw"
1027+
assert getreportopt(config) == "sfx"
10091028

10101029
config.option.reportchars = "sfxw"
1011-
assert getreportopt(config) == "sfxw"
1030+
assert getreportopt(config) == "sfx"
10121031

10131032
config.option.reportchars = "a"
1014-
assert getreportopt(config) == "sxXwEf" # NOTE: "w" included!
1033+
assert getreportopt(config) == "sxXEf"
10151034

10161035
config.option.reportchars = "A"
1017-
assert getreportopt(config) == "PpsxXwEf"
1036+
assert getreportopt(config) == "PpsxXEf"
1037+
1038+
config.option.reportchars = "AN"
1039+
assert getreportopt(config) == ""
1040+
1041+
config.option.reportchars = "NwfE"
1042+
assert getreportopt(config) == "fE"
10181043

10191044

10201045
def test_terminalreporter_reportopt_addopts(testdir):
@@ -1131,7 +1156,7 @@ def test_func():
11311156
)
11321157
for tbopt in ["long", "short", "no"]:
11331158
print("testing --tb=%s..." % tbopt)
1134-
result = testdir.runpytest("--tb=%s" % tbopt)
1159+
result = testdir.runpytest("-rN", "--tb=%s" % tbopt)
11351160
s = result.stdout.str()
11361161
if tbopt == "long":
11371162
assert "print(6*7)" in s

0 commit comments

Comments
 (0)