Pytest:打印到控制台并在junit报告中捕获输出?

zrfyljdw  于 2022-11-11  发布在  其他
关注(0)|答案(2)|浏览(172)

这将在junit中捕获stdout,但不会打印它

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

这将不会在junit中捕获stdout,而是将其打印出来

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

我如何允许pytest打印到stdout并将stdout打印到junitxml?

yiytaume

yiytaume1#

对于pytest-2.3.5,我们可以生成类似的junit-xml输出

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

我在www.example.com上进行file.py了pytest测试。--verbose命令行参数只是为了在控制台上输出详细的测试结果。
我还尝试通过从另一个python脚本调用我的测试脚本来生成类似的xml文件。

pytest.main(["--verbose","--junitxml=filepath\\file.xml","filepath\\file.py"])
k5ifujac

k5ifujac2#

以下命令可用于将输出打印到stdout/stderr,也可用于捕获到junit报告(从pytest 5.4开始):
python -m pytest --capture=tee-sys -o junit_logging=all --junit-xml=pytest_unit.xml tests/test_something.py
--capture=tee-sys和junit_logging=all的文档

相关问题