Skip to content

--no-summary disables the pytest_terminal_summary hook, silencing third-party plugins as well as pytest's own summary #14724

Description

@dprada

--no-summary reads as a presentational flag — its help text is Disable summary, and the documentation describes it among the options that control what the terminal prints. What it actually does is skip calling the pytest_terminal_summary hook, which is the documented extension point every reporting plugin writes through. Silencing pytest therefore silences every other plugin too.

_pytest/terminal.py, unchanged between 8.4.2 and 9.1.1:

if exitstatus in summary_exit_codes and not self.no_summary:
    self.config.hook.pytest_terminal_summary(
        terminalreporter=self, exitstatus=exitstatus, config=self.config
    )

Reproduced on 9.1.1 with pytest-cov 7.1.0:

# mymod.py
def add(a, b): return a + b

# test_m.py
from mymod import add
def test_add(): assert add(1, 2) == 3
$ pytest --cov=. --cov-report=term
================================ tests coverage ================================
Name        Stmts   Miss  Cover
-------------------------------
mymod.py        1      0   100%
test_m.py       2      0   100%
-------------------------------
TOTAL           3      0   100%
============================== 1 passed in 0.05s ===============================

$ pytest --no-summary --cov=. --cov-report=term
============================== 1 passed in 0.05s ===============================

The coverage table is gone. Nothing warns that it was suppressed, and the user asked for --cov-report=term explicitly. Any plugin that reports through the hook behaves the same way.

We hit this from the other side, writing a reporting plugin that renders its own summary and therefore wants pytest's suppressed. --no-summary is the obvious switch, and we shipped it — swallowing the coverage report of every project that combined the two. It was found by a downstream project running the two plugins together, not by us.

The workaround is reportchars = "", which suppresses the short test summary info sections while leaving the hook intact. That works, but it is not discoverable from the option's name or its help text, and it is not what --no-summary appears to offer.

Two things are tangled here that seem separable:

  • pytest's own summary sections — what a user passing --no-summary almost certainly means.
  • the hook that third-party plugins write through — which the flag currently disables as a side effect.

Options, roughly in order of how invasive they are:

  1. Document it. The cheapest fix: state on --no-summary that it disables third-party terminal reporting as well, and point to reportchars for suppressing only pytest's sections.
  2. Move the gate inside pytest's own pytest_terminal_summary implementation, so the hook is still called and other plugins still report. This changes behaviour for anyone relying on the current effect, which is why we are not proposing it outright.
  3. Separate the two, e.g. --no-summary keeping its meaning for pytest's sections and a distinct mechanism for suppressing the hook entirely.

Related: this is the same line that omits INTERNAL_ERROR from summary_exit_codes, so pytest_terminal_summary is also never called when pytest fails internally — which is when a consumer most needs a plugin's output. Mentioned in passing rather than as part of this report; happy to split it out if it is worth its own issue.

Context for both this and #14720: we are building a reporting plugin at https://github.com/uibcdf/pytest-receptor and these are the two places where the extension surface fought us.

Happy to send a documentation patch for option 1 if that is the direction the team prefers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions