Skip to content

Commit deb9f5f

Browse files
authored
Add a space after the test name with --setup-show (#14430)
Before, a test's result was printed immediately after --setup-show output: SETUP F fixt test_show.py::test_a (fixtures used: fixt)PASSED TEARDOWN F fixt In the extreme case, with monochrome output or yellow and white colors being close to each other, an "x" for an xfailing test can be misinterpreted as part of a test name: test_show.py::test_xfailx This adds a space to clearly distinguish the output: test_show.py::test_a (fixtures used: fixt) PASSED and test_show.py::test_xfail x
1 parent 2aa0734 commit deb9f5f

4 files changed

Lines changed: 10 additions & 6 deletions

File tree

changelog/14430.improvement.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
When using ``--setup-show``, a space is now printed after the test name (and possibly used fixtures), to separate it from the test result.

src/_pytest/runner.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,10 @@ def runtestprotocol(
132132
rep = call_and_report(item, "setup", log)
133133
reports = [rep]
134134
if rep.passed:
135+
setup_only = item.config.getoption("setuponly", False)
135136
if item.config.getoption("setupshow", False):
136-
show_test_item(item)
137-
if not item.config.getoption("setuponly", False):
137+
show_test_item(item, add_space=not setup_only)
138+
if not setup_only:
138139
reports.append(call_and_report(item, "call", log))
139140
# If the session is about to fail or stop, teardown everything - this is
140141
# necessary to correctly report fixture teardown errors (see #11706)
@@ -150,7 +151,7 @@ def runtestprotocol(
150151
return reports
151152

152153

153-
def show_test_item(item: Item) -> None:
154+
def show_test_item(item: Item, *, add_space: bool) -> None:
154155
"""Show test function, parameters and the fixtures of the test item."""
155156
tw = item.config.get_terminal_writer()
156157
tw.line()
@@ -159,6 +160,8 @@ def show_test_item(item: Item) -> None:
159160
used_fixtures = sorted(getattr(item, "fixturenames", []))
160161
if used_fixtures:
161162
tw.write(f" (fixtures used: {', '.join(used_fixtures)})")
163+
if add_space:
164+
tw.write(" ")
162165
tw.flush()
163166

164167

testing/python/fixtures.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4433,11 +4433,11 @@ def test_second(my_fixture):
44334433
[
44344434
"test_fixtures.py::test_first ",
44354435
" SETUP F my_fixture",
4436-
" test_fixtures.py::test_first (fixtures used: my_fixture, request)PASSED",
4436+
" test_fixtures.py::test_first (fixtures used: my_fixture, request) PASSED",
44374437
"test_fixtures.py::test_first ERROR",
44384438
"test_fixtures.py::test_second ",
44394439
" SETUP F my_fixture",
4440-
" test_fixtures.py::test_second (fixtures used: my_fixture, request)PASSED",
4440+
" test_fixtures.py::test_second (fixtures used: my_fixture, request) PASSED",
44414441
" TEARDOWN F my_fixture",
44424442
],
44434443
consecutive=True,

testing/test_setuponly.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ def test_arg(arg):
276276
assert result.ret == 1
277277

278278
result.stdout.fnmatch_lines(
279-
["*SETUP F arg*", "*test_arg (fixtures used: arg)F*", "*TEARDOWN F arg*"]
279+
["*SETUP F arg*", "*test_arg (fixtures used: arg) F*", "*TEARDOWN F arg*"]
280280
)
281281

282282

0 commit comments

Comments
 (0)