pytest icon indicating copy to clipboard operation
pytest copied to clipboard

Inclusion of capteesys in pytest function and run with -s causes doubled prints to stdout

Open jameszianxuTT opened this issue 2 months ago • 0 comments

See simple example:

import sys

def test_dummy_test_with_traceback(request, capteesys):
    print(f"Hello world stdout", flush=True)
    print(f"Hello world stderr",file=sys.stderr, flush=True)

Run with:

$ pytest -svv test.py
============================================================================================================================= test session starts =============================================================================================================================
platform linux -- Python 3.11.13, pytest-8.4.1, pluggy-1.6.0 -- /localdev/user/clean/tt-xla/venv/bin/python
cachedir: .pytest_cache
rootdir: /localdev/user/clean/tt-xla
configfile: pytest.ini
plugins: forked-1.6.0, split-0.10.0, jaxtyping-0.3.3
collected 1 item                                                                                                                                                                                                                                                              

test.py::test_dummy_test_with_traceback Hello world stdout
Hello world stderr
Hello world stdout
Hello world stderr
PASSED

============================================================================================================================== 1 passed in 0.01s ==============================================================================================================================

Is this intended behavior? I am not even using capteesys, just including it in the test function signature.

pytest-8.4.1, 8.4.2 both display this behavior.

jameszianxuTT avatar Oct 03 '25 16:10 jameszianxuTT