Pytest-test-execution-results-in-xml-format
提供:Dev Guides
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>タグは、失敗したテストコードの詳細を提供します。