Skip to content

CliRunner does not capture logging output on stdout #854

Closed

Description

@blueyed

Is this expected?

It feels like a missing feature, so I'd be happy to provide it giving some pointers.

My test:

def test_cli_run_with_args(runner):
    result = runner.invoke(cli.main, ['run', 'printf', '%s', '--'])
    …

And in the run command I have:

logger.warn('The temporary profile file (%s) has not been created.',
            profile_file_name)

Where logger is logger = logging.getLogger('covimerage'), which gets setup in __init__.py:

logger = logging.getLogger('covimerage')
logger.setLevel(logging.INFO)
logger.addHandler(logging.StreamHandler(sys.stdout))

When run manually the warning shows up.

It also shows up in pytest's Captured stdout call.

Activity

  1. blueyed commented on Oct 1, 2017

    @blueyed
    ContributorAuthor

    That is more a problem of logging using not sys.stdout / sys.stderr directly, but where it pointed at when the handler gets created, and is therefore kind of expected.

    As for me, I am using a handler based on logging's own _StderrHandler that will use sys.stderr always.

  2. locked as resolved and limited conversation to collaborators on Nov 13, 2020
  3. changed the title [-]CliRunner does not capture logging output on stdout[/-] [+]`CliRunner` does not capture `logging` output on `stdout`[/+] on Apr 29, 2026
  4. added this to the 8.4.0 milestone on Apr 29, 2026
  5. added
    test runner
    on Apr 29, 2026
  6. 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.

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