2016-05-13 225 views
1

有沒有一種方法來捕捉測試統計數據(通過/失敗/ xfail /跳過)使用Python代碼從調用pytest當計數訪問Pytest通過/失敗計數(測試數據)的代碼

exit_code = pytest.main() 

pytest測試完成後,我想收集這些統計信息以作進一步處理。我現在所能想到的就是編寫插件並訪問「terminalreporter」插件統計信息,但如果有更好,更簡單的方法來做到這一點,我很想知道。

回答

0

不是一個真正的好的解決方案(恕我直言),但它似乎/失敗,增加使用pytest_runtest_logreport(self,report)掛鉤合作 對運行/計數器傳遞

if report.when == "setup": 
    test_run += 1 
if report.passed and report.when == "teardown": 
    test_passed += 1 
if not report.passed and report.outcome != 'skipped': 
    test_failed += 1