Closed bored002 closed 1 year ago
Hi @bored002,
Hmm that's strange, it works for me:
import sys
def test_foo():
sys.stdout.write("this is stdout from test_foo")
sys.stderr.write("this is stderr from test_foo")
assert 0
def test_bar():
sys.stdout.write("this is stdout from test_bar")
sys.stderr.write("this is stderr from test_bar")
λ pytest .tmp\test_junit.py -v --cache-clear --durations=0 --junitxml=foo.xml --tb=long -o junit_logging=all -o junit_family=legacy -q
======================== test session starts ========================
platform win32 -- Python 3.8.8, pytest-6.3.0.dev797+g2af41c570.d20211022, py-1.10.0, pluggy-0.13.1
rootdir: e:\projects\pytest\.tmp, configfile: pytest.ini
plugins: hypothesis-6.8.1
collecting ... <Function test_foo>
<Function test_bar>
collected 2 items
.tmp\test_junit.py F. [100%]
============================= FAILURES ==============================
_____________________________ test_foo ______________________________
def test_foo():
sys.stdout.write("this is stdout from test_foo")
sys.stderr.write("this is stderr from test_foo")
> assert 0
E assert 0
.tmp\test_junit.py:6: AssertionError
----------------------- Captured stdout call ------------------------
this is stdout from test_foo
----------------------- Captured stderr call ------------------------
this is stderr from test_foo
---------- generated xml file: e:\projects\pytest\foo.xml -----------
========================= slowest durations =========================
(6 durations < 0.005s hidden. Use -vv to show these durations.)
====================== short test summary info ======================
FAILED .tmp\test_junit.py::test_foo - assert 0
==================== 1 failed, 1 passed in 0.10s ====================
Output:
<?xml version="1.0" encoding="utf-8"?><testsuites><testsuite name="pytest" errors="0" failures="1" skipped="0" tests="2" time="0.065" timestamp="2021-11-10T09:39:12.280543" hostname="DESKTOP-31D77J6"><testcase classname="test_junit" name="test_foo" file="test_junit.py" line="2" time="0.001"><failure message="assert 0">def test_foo():
sys.stdout.write("this is stdout from test_foo")
sys.stderr.write("this is stderr from test_foo")
> assert 0
E assert 0
.tmp\test_junit.py:6: AssertionError</failure><system-out>--------------------------------- Captured Log ---------------------------------
--------------------------------- Captured Out ---------------------------------
this is stdout from test_foo
</system-out><system-err>--------------------------------- Captured Err ---------------------------------
this is stderr from test_foo
</system-err></testcase><testcase classname="test_junit" name="test_bar" file="test_junit.py" line="7" time="0.001"><system-out>--------------------------------- Captured Log ---------------------------------
--------------------------------- Captured Out ---------------------------------
this is stdout from test_bar
</system-out><system-err>--------------------------------- Captured Err ---------------------------------
this is stderr from test_bar
</system-err></testcase></testsuite></testsuites>
Can you please provide a MWE?
Anyway, i found that i was missing in the invocation : '-o','junit_logging=out-err' It seems to solve the issue.
But your pytest.ini
already contains that setting (actually uses all
), no?
Or the problem is that pytest.main
was not picking up the configuration file?
@nicoddemus yea so it would seem but , it might be related that it's only in the root dir of the project , might this be the issue?
This issue is stale because it has been open for 14 days with no activity.
@bored002 you still having these issue? (Sorry for not answering before, this fell through the cracks)
This issue is stale because it has been open for 14 days with no activity.
i resolved by calling the junit output flags in the pytest.main invocation
This issue is stale because it has been open for 14 days with no activity.
This issue was closed because it has been inactive for 7 days since being marked as stale.
Description When using pytest to generate junitxml report the captured stdout/stderrr and not shown in the xml file itsel
Operating System: Windows 10 -64bit
Pytest.ini content:
invoking pytest :
exit_code = pytest.main(['-v', '--cache-clear','test_pytest.py', '--durations=0', '--junitxml', junit_path, '--tb', 'long'])