Skip to content

CliRunner.invoke doesn't capture stdout from logging #2761

Closed

Description

@mjperrone

This is a revival of #2497

I am hitting the issue described in that issue when using CliRunner. It is preventing me from being able to test the stdout and stderr of my click CLI commands.

The previous issue was closed with @davidism saying "Duplicate of existing issues about pretest's logging capture." Since I am unable to comment on that issue, I am creating a new one.

I would love to be pointed at the referenced duplicate issue so I can understand better what the issue and solutions are.

Ideally I would love to see some kind of workaround documented: Is there a way I can use python's builtin logging library in a way that would allow CliRunner to capture the output?

Activity

  1. davidism commented on Aug 8, 2024

    @davidism
    Member

    Here are issues mentioning pytest: https://github.com/pallets/click/issues?q=is%3Aissue+pytest
    Here are issues mentioning logging: https://github.com/pallets/click/issues?q=is%3Aissue+logging
    Here's an open one mentioning both: #824

    Happy to review PRs fixing this, but I haven't personally had issues with it so I'm not in the best position to investigate and fix it. Closing this as I think the existing issues cover it.

  2. locked as resolved and limited conversation to collaborators on Aug 23, 2024
  3. added
    test runner
    on Apr 29, 2026
  4. added this to the 8.4.0 milestone on Apr 29, 2026
  5. kdeldycke commented on Apr 29, 2026

    @kdeldycke
    Collaborator

    This is going to be addressed in v8.4.0 by #3391 which introduce a new capture="fd" mode to CliRunner.

  6. changed the title [-]CliRunner.invoke doesn't capture stdout from logging[/-] [+]`CliRunner.invoke` doesn't capture `stdout` from `logging`[/+] on Apr 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    test runner

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions