Skip to content

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

@jameszianxuTT

Description

@jameszianxuTT

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions