4
让我们用下面的代码(conftest.py):如何使用junitxml在pytest中收集数据结果?
import random
def test_val():
value = random.random()
assert value < 0.5
运行py.test --junitxml=result.xml conftest.py
产生result.xml
(当测试通过):
<?xml version="1.0" encoding="utf-8"?>
<testsuite errors="0" failures="0" name="" skips="0" tests="1" time="0.047">
<testcase classname="conftest" name="test_val" time="0.0"/>
</testsuite>
现在。我希望能够做的是将test_val()
生成的值存储在results.xml
中。有没有办法做到这一点?我似乎无法找到pytest doc中的任何相关内容。
可能是单元测试的老问题;测试应该通过或失败 - 没有别的: - 只有在失败的情况下才会考虑消息。 – Alfe 2012-03-21 13:05:59
这是非常不幸的:( – 2012-03-23 16:14:09
那么,在第一种情况下,如果测试失败,你会得到py.test输出中的实际结果。另一种选择是使用jenkins运行py.test并获取一些报告通过/失败......),最终目标是通过或失败,只有当你失败时才会感兴趣。 – 2012-09-03 06:12:47