Pytest支持以下幾種測試Report逃默,跟著我一起來學(xué)習(xí)吧!
在你的PyCharm工程中新建test_one_func.py文件于宙,然后在Terminal中運(yùn)行下面的實(shí)例摩梧,檢查有沒有生成對應(yīng)的Report。
在你的工程對應(yīng)的目錄下建立一個(gè)新文件夾:report卖漫,你也可以在其他目錄創(chuàng)建费尽。
新建文件夾report
###This is test_one_func.py
def func(x):
return x + 1
def test_func():
assert func(3) == 5
1. 生成JunitXML 格式的測試報(bào)告
JunitXML報(bào)告是一種很常用的測試報(bào)告,比如可以和Jenkins進(jìn)行集成羊始,在Jenkins的GUI上顯示Pytest的運(yùn)行結(jié)果旱幼,非常便利。
運(yùn)行完case后可以到report路徑下去查看相應(yīng)的xml文件突委,也可以在PyCharm打開該xml文件查看柏卤。
運(yùn)行
pytest --junitxml=path
#絕對路徑:
pytest -v test_one_func.py --junitxml=C:\Users\yatyang\PycharmProjects\pytest_example\report\test_one_func.xml
#相對路徑
pytest -v test_one_func.py --junitxml=report\test_one_func.xml
生成JunitXML Report.png
test_one_func.xml 內(nèi)容
2. 生成result log格式的測試報(bào)告
txt也是最簡單的一種測試報(bào)告,實(shí)例如下匀油。運(yùn)行完case后可以到report路徑下去查看相應(yīng)的txt文件闷旧,也可以在PyCharm打開該txt文件查看。
pytest -v test_one_func.py --resultlog=report\log.txt
生成log Report.png
3. 生成Html格式的測試報(bào)告
html格式的測試報(bào)告在瀏覽器觀看效果很好钧唐,還可以把這些測試報(bào)告放在Web服務(wù)器上忙灼。
首先,需要安裝pytest-html插件钝侠。
pip install pytest-html
安裝pytest-html插件.png
pytest -v test_one_func.py --html=report\test_one_func.html
這個(gè)report的格式還是很漂亮的该园,有Environment,Summary和Report帅韧,非常友好里初。
test_one_func.html
最后,如果你的report文件夾內(nèi)正確生成了上面介紹的這三種格式的測試報(bào)告忽舟,恭喜你双妨!
pytest的3種Report