pytest-subtests icon indicating copy to clipboard operation
pytest-subtests copied to clipboard

Captured stdout for a subtest is not displayed properly

Open yugokato opened this issue 2 years ago • 1 comments
trafficstars

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. (https://github.com/pytest-dev/pytest-html/issues/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

yugokato avatar Oct 23 '23 15:10 yugokato

My suspicion here is this has something to do with the -rA flag. This plugin captures output here so I suspect we'd need to add something which looks at the -rA flag similar to here in terminal.py.

Although I'm not clear how that impacts the html report

rhoban13 avatar Jan 26 '24 16:01 rhoban13