Show print output while pytest runs
Disable stream capture for serial debugging, use tee capture when you still need reports, and configure live logging separately from print output.
For a normal serial run, use python -m pytest -s. The -s option is shorthand for --capture=no, which disables pytest's standard output/error capture.
python -m pytest -s
python -m pytest tests/test_api.py -s -v
Pytest normally captures stdout and stderr so successful tests do not flood the result summary. Captured output is typically shown with a failure report. A print statement that appears to do nothing may simply be captured.
Choose a capture mode
python -m pytest --capture=tee-sys
python -m pytest --show-capture=no
python -m pytest -q -s
tee-sys both captures and passes through writes to Python's sys.stdout and sys.stderr. It is not equivalent to teeing every low-level file-descriptor or subprocess write. The default fd capture covers a broader class of stream writes on supported systems.
--show-capture=no hides captured sections in reports; it does not disable capture. -q reduces pytest's own progress verbosity and is independent of application printing.
Disabling pytest capture cannot remove buffering in the application, subprocess, terminal, or CI log transport. Use print(..., flush=True) when an immediate Python-level flush is needed, while checking the rest of the pipeline too.
Configure logging separately
python -m pytest --log-cli-level=INFO
This enables live logging at the selected level while stdout/stderr can remain captured. Pytest's logging plugin and normal stream capture are separate mechanisms. -s does not automatically turn every logger's INFO or DEBUG records into visible output; logger levels, handlers, filters, and pytest logging settings still apply.
For assertions about printed text, the capsys fixture is often better than watching the terminal:
def test_message(capsys):
print("Operation complete")
captured = capsys.readouterr()
assert captured.out == "Operation complete\n"
Capture fixtures such as capsys take precedence over the global capture setting, so the test above can still capture its output when the suite runs with -s.
FAQ
Do I need -s for pdb?
Pytest temporarily suspends capture when entering its integrated debugger, including normal breakpoint()/--pdb workflows. A serial run is easiest to inspect interactively.
Does -s stream prints from xdist workers?
No. Xdist does not forward worker stdout/stderr this way. Run the failing selection without xdist, or with -n 0, for ordinary interactive output. Captured failure reports and deliberately configured per-worker files are alternatives for distributed diagnosis.
Can I see logs while keeping print output captured?
Yes. Use live logging, such as --log-cli-level=DEBUG, without disabling stream capture. Keep output levels appropriate for the test run and avoid logging credentials merely to diagnose a missing print.
References: pytest output capture, pytest logging, pytest-xdist limitations.
Contact us
Join the community
to join the community
Try Guance
Start online and pay only for what you use.
Get startedChoose a Guance plan