Skip to content

Commit ecd1e43

Browse files
authored
Make 'S' and 'F' aliases to 's' and 'f' respectively (#6337)
Make 'S' and 'F' aliases to 's' and 'f' respectively
2 parents cbb2f95 + 9b74bf1 commit ecd1e43

File tree

3 files changed

+46
-11
lines changed

3 files changed

+46
-11
lines changed

changelog/6334.bugfix.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix summary entries appearing twice when ``f/F`` and ``s/S`` report chars were used at the same time in the ``-r`` command-line option (for example ``-rFf``).
2+
3+
The upper case variants were never documented and the preferred form should be the lower case.

src/_pytest/terminal.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,11 @@ def getreportopt(config: Config) -> str:
172172
reportchars += "w"
173173
elif config.option.disable_warnings and "w" in reportchars:
174174
reportchars = reportchars.replace("w", "")
175+
aliases = {"F", "S"}
175176
for char in reportchars:
177+
# handle old aliases
178+
if char in aliases:
179+
char = char.lower()
176180
if char == "a":
177181
reportopts = "sxXwEf"
178182
elif char == "A":
@@ -185,19 +189,16 @@ def getreportopt(config: Config) -> str:
185189

186190
@pytest.hookimpl(trylast=True) # after _pytest.runner
187191
def pytest_report_teststatus(report: TestReport) -> Tuple[str, str, str]:
192+
letter = "F"
188193
if report.passed:
189194
letter = "."
190195
elif report.skipped:
191196
letter = "s"
192-
elif report.failed:
193-
letter = "F"
194-
if report.when != "call":
195-
letter = "f"
196197

197-
# Report failed CollectReports as "error" (in line with pytest_collectreport).
198198
outcome = report.outcome
199-
if report.when == "collect" and outcome == "failed":
199+
if report.when in ("collect", "setup", "teardown") and outcome == "failed":
200200
outcome = "error"
201+
letter = "E"
201202

202203
return outcome, letter, outcome.upper()
203204

@@ -988,9 +989,7 @@ def show_skipped(lines: List[str]) -> None:
988989
"x": show_xfailed,
989990
"X": show_xpassed,
990991
"f": partial(show_simple, "failed"),
991-
"F": partial(show_simple, "failed"),
992992
"s": show_skipped,
993-
"S": show_skipped,
994993
"p": partial(show_simple, "passed"),
995994
"E": partial(show_simple, "error"),
996995
} # type: Mapping[str, Callable[[List[str]], None]]

testing/test_terminal.py

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,35 @@ def test(i):
754754
result = testdir.runpytest(*params)
755755
result.stdout.fnmatch_lines(["collected 3 items", "hello from hook: 3 items"])
756756

757+
def test_summary_f_alias(self, testdir):
758+
"""Test that 'f' and 'F' report chars are aliases and don't show up twice in the summary (#6334)"""
759+
testdir.makepyfile(
760+
"""
761+
def test():
762+
assert False
763+
"""
764+
)
765+
result = testdir.runpytest("-rfF")
766+
expected = "FAILED test_summary_f_alias.py::test - assert False"
767+
result.stdout.fnmatch_lines([expected])
768+
assert result.stdout.lines.count(expected) == 1
769+
770+
def test_summary_s_alias(self, testdir):
771+
"""Test that 's' and 'S' report chars are aliases and don't show up twice in the summary"""
772+
testdir.makepyfile(
773+
"""
774+
import pytest
775+
776+
@pytest.mark.skip
777+
def test():
778+
pass
779+
"""
780+
)
781+
result = testdir.runpytest("-rsS")
782+
expected = "SKIPPED [1] test_summary_s_alias.py:3: unconditional skip"
783+
result.stdout.fnmatch_lines([expected])
784+
assert result.stdout.lines.count(expected) == 1
785+
757786

758787
def test_fail_extra_reporting(testdir, monkeypatch):
759788
monkeypatch.setenv("COLUMNS", "80")
@@ -1685,12 +1714,16 @@ def test_teardown_with_test_also_failing(
16851714
testdir.makepyfile(
16861715
"""
16871716
def test_foo(fail_teardown):
1688-
assert False
1717+
assert 0
16891718
"""
16901719
)
1691-
output = testdir.runpytest()
1720+
output = testdir.runpytest("-rfE")
16921721
output.stdout.re_match_lines(
1693-
[r"test_teardown_with_test_also_failing.py FE\s+\[100%\]"]
1722+
[
1723+
r"test_teardown_with_test_also_failing.py FE\s+\[100%\]",
1724+
"FAILED test_teardown_with_test_also_failing.py::test_foo - assert 0",
1725+
"ERROR test_teardown_with_test_also_failing.py::test_foo - assert False",
1726+
]
16941727
)
16951728

16961729
def test_teardown_many(self, testdir, many_files):

0 commit comments

Comments
 (0)