Skip to content

Commit 3579ffb

Browse files
committed
chore(fill): supress pytest-html terminal summary if no tests ran
I.e., don't print "`----------- Generated html report: file:///home...`" in the terminal summary as we delete the report in `pytest_sessionfinish()`.
1 parent 28510cb commit 3579ffb

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/pytest_plugins/filler/filler.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,9 +432,28 @@ def pytest_terminal_summary(
432432
Emphasize that fixtures have only been filled; they must now be executed to
433433
actually run the tests.
434434
"""
435-
yield
436435
if config.fixture_output.is_stdout or hasattr(config, "workerinput"): # type: ignore[attr-defined]
436+
yield
437437
return
438+
# if no tests were collected, suppress the "Generated html report" message;
439+
# the html report will be deleted in pytest_sessionfinish hook
440+
session = terminalreporter._session
441+
if getattr(session, "testscollected", 0) == 0:
442+
orig_write_sep = terminalreporter.write_sep
443+
444+
def filtered_write_sep(sep, msg, **kwargs):
445+
if isinstance(msg, str) and "Generated html report:" in msg:
446+
return # swallow it
447+
return orig_write_sep(sep, msg, **kwargs)
448+
449+
terminalreporter.write_sep = filtered_write_sep # type: ignore
450+
try:
451+
yield # let all other terminal_summary hooks run
452+
finally:
453+
terminalreporter.write_sep = orig_write_sep # type: ignore
454+
else:
455+
# if tests ran, no action needed, just yield to run the rest of the hooks
456+
yield
438457
stats = terminalreporter.stats
439458
if "passed" in stats and stats["passed"]:
440459
# Custom message for Phase 1 (pre-allocation group generation)

0 commit comments

Comments
 (0)