An un-flushed write to stderr, as with `print(..., file=sys.stderr)`, will end up flushed by the runner at end of invocation.
()
| 466 | |
| 467 | |
| 468 | def test_isolation_flushes_unflushed_stderr(): |
| 469 | """An un-flushed write to stderr, as with `print(..., file=sys.stderr)`, will end up |
| 470 | flushed by the runner at end of invocation. |
| 471 | """ |
| 472 | runner = CliRunner() |
| 473 | |
| 474 | with runner.isolation() as (_, err, _): |
| 475 | click.echo("\udce2", err=True, nl=False) |
| 476 | assert err.getvalue() == b"\\udce2" |
| 477 | |
| 478 | @click.command() |
| 479 | def cli(): |
| 480 | # set end="", flush=False so that it's totally clear that we won't get any |
| 481 | # auto-flush behaviors |
| 482 | print("gyarados gyarados gyarados", file=sys.stderr, end="", flush=False) |
| 483 | |
| 484 | result = runner.invoke(cli) |
| 485 | assert result.stderr == "gyarados gyarados gyarados" |
| 486 | |
| 487 | |
| 488 | def test_pdb_uses_real_streams(): |