Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pytest to be completely quiet when asked #13224

Open
kosarev opened this issue Feb 15, 2025 · 3 comments
Open

pytest to be completely quiet when asked #13224

kosarev opened this issue Feb 15, 2025 · 3 comments

Comments

@kosarev
Copy link

kosarev commented Feb 15, 2025

What's the problem this feature will solve?

There currently seems to be no easy way to make pytest not produce any output when all tests pass.

pytest --quiet --quiet ... fails to do what seems to be the most expected thing -- be quiet, still printing dots and progress information:

$ pytest --quiet --quiet
.......                                                                  [100%]

-o console_output_style=none silences the progress and the dots can be dealt with with a pytest_report_teststatus() hook, but:

  • the none only works because it's not one of the officially supported values for console_output_style and the code doesn't bother raising an error,
  • more importantly, using the option and the hook feels more work than what making pytest quiet should take and
  • crucially, even using the option and the hook pytest still emits an empty line.

The new line character seems to come from pytest_sessionfinish():

    @hookimpl(wrapper=True)
    def pytest_sessionfinish(
        self, session: Session, exitstatus: int | ExitCode
    ) -> Generator[None]:
        result = yield
        self._tw.line("")  # HERE

Describe the solution you'd like

I would expect pytest to support a command-line option or a set of options that together would make it not produce any output unless a test is failed.

Something like:

pytest --quiet --quiet --quiet ...
pytest --really-quiet ...
pytest --no-report-on-success ...

Alternative Solutions

Running chronic pytest ... helps, but prevents colour output.

Additional context

None.

@The-Compiler
Copy link
Member

The-Compiler commented Feb 15, 2025

I agree that -qq or -qqq would make sense for this, but I'm left wondering: Why? What's your use-case for this?

@kosarev
Copy link
Author

kosarev commented Feb 15, 2025

What's your use-case for this?

It is to suppress the output that distracts, drains attention and costs time to read through on every run just to make sure tests have passed.

In my development cycle tests passing is not an event deserving attention. Them failing is.

Here's more on the same matter: https://www.linfo.org/rule_of_silence.html

@belm0
Copy link

belm0 commented Feb 17, 2025

Use case: I want to test that nothing in the system under test is leaking stdout or stderr logs between tests

While for the stderr case I can use pytest --quiet > /dev/null, this will not catch log messages leaking on stdout.

(I don't understand why --quiet wouldn't apply to progress.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants