1. 生成JunitXML 格式的測試報告
JunitXML報告是一種很常用的測試報告,比如可以和Jenkins進行集成,在Jenkins的GUI上顯示Pytest的運行結果,非常便利。
運行完case后可以到report路徑下去查看相應的xml文件,也可以在PyCharm打開該xml文件查看。
運行
pytest --junitxml=path #絕對路徑: pytest -v test_one_func.py --junitxml=C:\Users\PycharmProjects\pytest_example\report\test_one_func.xml #相對路徑 pytest -v test_one_func.py --junitxml=report\test_one_func.xml
2. 生成result log格式的測試報告
txt也是最簡單的一種測試報告,實例如下。運行完case后可以到report路徑下去查看相應的txt文件,也可以在PyCharm打開該txt文件查看。
pytest -v test_one_func.py --resultlog=report\log.txt
3. 生成Html格式的測試報告
html格式的測試報告在瀏覽器觀看效果很好,還可以把這些測試報告放在Web服務器上。 首先,需要安裝pytest-html插件。
pip install pytest-html
pytest -v test_one_func.py --html=report\test_one_func.html