Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pytest: Print to console and capture output in the junit report?

Tags:

junit

pytest

This will capture stdout in junit but will not print it

py.test --verbose simpletest.py --junit-xml=test.xml

This will not capture stdout in junit and will print it

py.test --verbose --capture=no simpletest.py --junit-xml=test.xml

How do I allow pytest to print to stdout and print stdout to junit xml?

like image 333
SomeGuyOnAComputer Avatar asked Nov 09 '22 15:11

SomeGuyOnAComputer


1 Answers

For pytest-2.3.5 we can generate a similar junit-xml output

pytest --verbose --junitxml=filepath\\file.xml file.py

I tested this with file.py having pytest tests. --verbose command line argument is just to ouput detailed test results on console.

I also tried to generate a similar xml file by invoking my test script from another python script

pytest.main(["--verbose","--junitxml=filepath\\file.xml","filepath\\file.py"])
like image 99
RAD Avatar answered Jan 04 '23 01:01

RAD