Skip to content

Commit ca73965

Browse files
committed
terminal: default to fE with -r (reportchars)
Fixes #6454
1 parent 2f0d0fb commit ca73965

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
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).

src/_pytest/terminal.py

+8-4
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

+13-5
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,15 +918,20 @@ 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 = ""
925+
reportchars = _REPORTCHARS_DEFAULT
924926
disable_warnings = True
925927

926928
option = Option()
927929

928930
config = Config()
929931

932+
# Default.
933+
assert getreportopt(config) == "fE"
934+
930935
config.option.reportchars = "sf"
931936
assert getreportopt(config) == "sf"
932937

@@ -939,7 +944,7 @@ class Option:
939944
assert getreportopt(config) == "sxXwEf" # NOTE: "w" included!
940945

941946
config.option.reportchars = "sfx"
942-
assert getreportopt(config) == "sfxw"
947+
assert getreportopt(config) == "wsfx"
943948

944949
config.option.reportchars = "sfxw"
945950
assert getreportopt(config) == "sfxw"
@@ -950,6 +955,9 @@ class Option:
950955
config.option.reportchars = "A"
951956
assert getreportopt(config) == "PpsxXwEf"
952957

958+
config.option.reportchars = "AN"
959+
assert getreportopt(config) == ""
960+
953961

954962
def test_terminalreporter_reportopt_addopts(testdir):
955963
testdir.makeini("[pytest]\naddopts=-rs")
@@ -1065,7 +1073,7 @@ def test_func():
10651073
)
10661074
for tbopt in ["long", "short", "no"]:
10671075
print("testing --tb=%s..." % tbopt)
1068-
result = testdir.runpytest("--tb=%s" % tbopt)
1076+
result = testdir.runpytest("-rN", "--tb=%s" % tbopt)
10691077
s = result.stdout.str()
10701078
if tbopt == "long":
10711079
assert "print(6*7)" in s

0 commit comments

Comments
 (0)