- Pytest 教程
- Pytest - 主页
- Pytest - 简介
- Pytest - 环境设置
- 识别测试文件和函数
- Pytest - 从基本测试开始
- Pytest - 文件执行
- 执行测试套件的子集
- 测试名称的子串匹配
- Pytest - 分组测试
- Pytest - 固定装置
- Pytest - Conftest.py
- Pytest - 参数化测试
- Pytest - Xfail/跳过测试
- 在 N 个测试失败后停止测试套件
- Pytest - 并行运行测试
- XML 中的测试执行结果
- Pytest - 摘要
- Pytest - 结论
- Pytest 有用资源
- Pytest - 快速指南
- Pytest - 有用资源
- Pytest - 讨论
XML 格式的测试执行结果
我们可以在一个 xml 文件中生成测试执行的详细信息。此 xml 文件主要在我们需要一个投影测试结果的仪表盘的情况下很有用。在此类情况中,可以对 xml 进行解析以获取执行的详细信息。
我们现在将从 test_multiplcation.py 执行测试,并通过运行生成 xml
pytest test_multiplication.py -v --junitxml="result.xml"
现在可以发现 result.xml 已生成,其中包含以下数据 −
<?xml version = "1.0" encoding = "utf-8"?>
<testsuite errors = "0" failures = "1"
name = "pytest" skips = "0" tests = "4" time = "0.061">
<testcase classname = "test_multiplication"
file = "test_multiplication.py"
line = "2" name = "test_multiplication_11[1-11]"
time = "0.00117516517639>
</testcase>
<testcase classname = "test_multiplication"
file = "test_multiplication.py"
line = "2" name = "test_multiplication_11[2-22]"
time = "0.00155973434448">
</testcase>
<testcase classname = "test_multiplication"
file = "test_multiplication.py"
line = "2" name = "test_multiplication_11[3-35]" time = "0.00144290924072">
failure message = "assert (11 * 3) == 35">num = 3, output = 35
@pytest.mark.parametrize("num,
output",[(1,11),(2,22),(3,35),(4,44)])
def test_multiplication_11(num, output):>
assert 11*num == output
E assert (11 * 3) == 35
test_multiplication.py:5: AssertionErro
</failure>
</testcase>
<testcase classname = "test_multiplication"
file = "test_multiplication.py"
line = "2" name = "test_multiplication_11[4-44]"
time = "0.000945091247559">
</testcase>
</testsuite>
此处,<testsuit> 标记总结了有 4 个测试,其中失败数量为 1。
<testcase> 标记提供了每个已执行测试的详细信息。
<failure> 标记提供了失败的测试代码的详细信息。
广告