Skip to content
Myr

flush sys.stderr when CliRunner.invoke finalizes

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Stephen Rosen · committed by David Lord · parent b7cf069 · Browse files · 3 files+23 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+23 added−0 removed

  • tests:+21 added−0 removed
  • other:+2 added−0 removed

3 files+23 added−0 removed

modified:src/click/testing.py+1 added
508 unmodified lines
509 exit_code = 1510 exc_info = sys.exc_info()511 finally:512 sys.stdout.flush()513 sys.stderr.flush()514 stdout = outstreams[0].getvalue()515 stderr = outstreams[1].getvalue()516 output = outstreams[2].getvalue()517
41 unmodified lines
modified:tests/test_testing.py+21 added
448 unmodified lines
449 with runner.isolation() as (_, err, _):450 click.echo("\udce2", err=True, nl=False)451452 assert err.getvalue() == b"\\udce2"453454455def test_isolation_flushes_unflushed_stderr():456 """An un-flushed write to stderr, as with `print(..., file=sys.stderr)`, will end up457 flushed by the runner at end of invocation.458 """459 runner = CliRunner()460461 with runner.isolation() as (_, err, _):462 click.echo("\udce2", err=True, nl=False)463464 assert err.getvalue() == b"\\udce2"465466 @click.command()467 def cli():468 # set end="", flush=False so that it's totally clear that we won't get any469 # auto-flush behaviors470 print("gyarados gyarados gyarados", file=sys.stderr, end="", flush=False)471472 result = runner.invoke(cli)473 assert result.stderr == "gyarados gyarados gyarados"
modified:CHANGES.rst+1 added
4 unmodified lines
56- Fix flag value handling for flag options with a provided type. :issue:`2894`7 :issue:`2897` :pr:`2930`8- Fix shell completion for nested groups. :issue:`2906` :pr:`2907`9- Flush ``sys.stderr`` at the end of ``CliRunner.invoke``. :issue:`2682`1011Version 8.2.012-------------13
1231 unmodified lines