
- 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> 標記提供了失敗的測試程式碼的詳細資訊。
廣告