Skip to content

Captured stdout for a subtest is not displayed properly #110

Open
@yugokato

Description

@yugokato

Captured stdout for a subtest is not displayed when the --capture option value is fd or sys. It is displayed as expected when the value is tee-sys.
This causes pytest-html plugin not to be able to display them in a report either. (pytest-dev/pytest-html#750)

Minimum code to reproduce:

def test_something(subtests):
    print("main test")

    with subtests.test("subtest"):
        print("sub test")

Logs:

  • --capture=fd (or sys)
$ pytest -rA 
============================================================ test session starts =============================================================
platform darwin -- Python 3.9.18, pytest-7.4.2, pluggy-1.3.0
rootdir: /Users/yugo/Desktop/test
plugins: subtests-0.11.0
collected 1 item                                                                                                                             

test_something.py ,.                                                                                                                   [100%]

=================================================================== PASSES ===================================================================
_______________________________________________________________ test_something _______________________________________________________________
------------------------------------------------------------ Captured stdout call ------------------------------------------------------------
main test
========================================================== short test summary info ===========================================================
PASSED test_something.py::test_something
==================================================== 1 passed, 1 subtests passed in 0.02s ====================================================
  • --capture=tee-sys
$ pytest -rA --capture=tee-sys
============================================================ test session starts =============================================================
platform darwin -- Python 3.9.18, pytest-7.4.2, pluggy-1.3.0
rootdir: /Users/yugo/Desktop/test
plugins: subtests-0.11.0
collected 1 item                                                                                                                             

test_something.py main test
sub test
,.                                                                                                                   [100%]

=================================================================== PASSES ===================================================================
_______________________________________________________________ test_something _______________________________________________________________
------------------------------------------------------------ Captured stdout call ------------------------------------------------------------
main test
sub test
========================================================== short test summary info ===========================================================
PASSED test_something.py::test_something
==================================================== 1 passed, 1 subtests passed in 0.02s ====================================================
$ pip freeze
attrs==23.1.0
exceptiongroup==1.1.3
iniconfig==2.0.0
packaging==23.2
pluggy==1.3.0
pytest==7.4.2
pytest-subtests==0.11.0
tomli==2.0.1

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