Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/14430.improvement.rst
Original file line number Diff line number Diff line change
@@ -0,0 +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.
9 changes: 6 additions & 3 deletions src/_pytest/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,10 @@ def runtestprotocol(
rep = call_and_report(item, "setup", log)
reports = [rep]
if rep.passed:
setup_only = item.config.getoption("setuponly", False)
if item.config.getoption("setupshow", False):
show_test_item(item)
if not item.config.getoption("setuponly", False):
show_test_item(item, add_space=not setup_only)
if not setup_only:
reports.append(call_and_report(item, "call", log))
# If the session is about to fail or stop, teardown everything - this is
# necessary to correctly report fixture teardown errors (see #11706)
Expand All @@ -150,7 +151,7 @@ def runtestprotocol(
return reports


def show_test_item(item: Item) -> None:
def show_test_item(item: Item, *, add_space: bool) -> None:
"""Show test function, parameters and the fixtures of the test item."""
tw = item.config.get_terminal_writer()
tw.line()
Expand All @@ -159,6 +160,8 @@ def show_test_item(item: Item) -> None:
used_fixtures = sorted(getattr(item, "fixturenames", []))
if used_fixtures:
tw.write(f" (fixtures used: {', '.join(used_fixtures)})")
if add_space:
tw.write(" ")
tw.flush()


Expand Down
4 changes: 2 additions & 2 deletions testing/python/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -4433,11 +4433,11 @@ def test_second(my_fixture):
[
"test_fixtures.py::test_first ",
" SETUP F my_fixture",
" test_fixtures.py::test_first (fixtures used: my_fixture, request)PASSED",
" test_fixtures.py::test_first (fixtures used: my_fixture, request) PASSED",
"test_fixtures.py::test_first ERROR",
"test_fixtures.py::test_second ",
" SETUP F my_fixture",
" test_fixtures.py::test_second (fixtures used: my_fixture, request)PASSED",
" test_fixtures.py::test_second (fixtures used: my_fixture, request) PASSED",
" TEARDOWN F my_fixture",
],
consecutive=True,
Expand Down
2 changes: 1 addition & 1 deletion testing/test_setuponly.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def test_arg(arg):
assert result.ret == 1

result.stdout.fnmatch_lines(
["*SETUP F arg*", "*test_arg (fixtures used: arg)F*", "*TEARDOWN F arg*"]
["*SETUP F arg*", "*test_arg (fixtures used: arg) F*", "*TEARDOWN F arg*"]
)


Expand Down