Skip to content

Commit 3ccf2a5

Browse files
authored
Merge pull request #6524 from blueyed/reportchars-default
terminal: default to `fE` with `-r` (reportchars)
2 parents e440b43 + ddaa5d8 commit 3ccf2a5

File tree

5 files changed

+65
-28
lines changed

5 files changed

+65
-28
lines changed

changelog/6454.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
`--disable-warnings` is honored with `-ra` and `-rA`.

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: 19 additions & 13 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",
@@ -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

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -814,9 +814,9 @@ def test():
814814
def test_fail_extra_reporting(testdir, monkeypatch):
815815
monkeypatch.setenv("COLUMNS", "80")
816816
testdir.makepyfile("def test_this(): assert 0, 'this_failed' * 100")
817-
result = testdir.runpytest()
817+
result = testdir.runpytest("-rN")
818818
result.stdout.no_fnmatch_line("*short test summary*")
819-
result = testdir.runpytest("-rf")
819+
result = testdir.runpytest()
820820
result.stdout.fnmatch_lines(
821821
[
822822
"*test summary*",
@@ -985,37 +985,62 @@ def test_this(i):
985985

986986

987987
def test_getreportopt():
988+
from _pytest.terminal import _REPORTCHARS_DEFAULT
989+
988990
class Config:
989991
class Option:
990-
reportchars = ""
991-
disable_warnings = True
992+
reportchars = _REPORTCHARS_DEFAULT
993+
disable_warnings = False
992994

993995
option = Option()
994996

995997
config = Config()
996998

999+
assert _REPORTCHARS_DEFAULT == "fE"
1000+
1001+
# Default.
1002+
assert getreportopt(config) == "wfE"
1003+
9971004
config.option.reportchars = "sf"
998-
assert getreportopt(config) == "sf"
1005+
assert getreportopt(config) == "wsf"
9991006

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

10031022
# Now with --disable-warnings.
1004-
config.option.disable_warnings = False
1023+
config.option.disable_warnings = True
10051024
config.option.reportchars = "a"
1006-
assert getreportopt(config) == "sxXwEf" # NOTE: "w" included!
1025+
assert getreportopt(config) == "sxXEf"
10071026

10081027
config.option.reportchars = "sfx"
1009-
assert getreportopt(config) == "sfxw"
1028+
assert getreportopt(config) == "sfx"
10101029

10111030
config.option.reportchars = "sfxw"
1012-
assert getreportopt(config) == "sfxw"
1031+
assert getreportopt(config) == "sfx"
10131032

10141033
config.option.reportchars = "a"
1015-
assert getreportopt(config) == "sxXwEf" # NOTE: "w" included!
1034+
assert getreportopt(config) == "sxXEf"
10161035

10171036
config.option.reportchars = "A"
1018-
assert getreportopt(config) == "PpsxXwEf"
1037+
assert getreportopt(config) == "PpsxXEf"
1038+
1039+
config.option.reportchars = "AN"
1040+
assert getreportopt(config) == ""
1041+
1042+
config.option.reportchars = "NwfE"
1043+
assert getreportopt(config) == "fE"
10191044

10201045

10211046
def test_terminalreporter_reportopt_addopts(testdir):
@@ -1132,7 +1157,7 @@ def test_func():
11321157
)
11331158
for tbopt in ["long", "short", "no"]:
11341159
print("testing --tb=%s..." % tbopt)
1135-
result = testdir.runpytest("--tb=%s" % tbopt)
1160+
result = testdir.runpytest("-rN", "--tb=%s" % tbopt)
11361161
s = result.stdout.str()
11371162
if tbopt == "long":
11381163
assert "print(6*7)" in s

0 commit comments

Comments
 (0)