一.前言
pytest-html可以为pytest生成一个显示测试结果的网页。这个HTML报告可以对测试结果(通过,跳过,失败,错误,预期失败,预期失败但通过)进行筛选,还可以按测试名称,持续时间,结果状态来排序。HTML报告还可以定制一些元素,如数据集的截图等
二.使用
安装:
pip install pytest-html==2.1.0
目录结构
test_menus1.py
# encoding=utf-8
import pytest
import logging
import random
import time
@pytest.mark.smoke
class TestMenus:
@pytest.mark.skipif(24<8,reason='版本不匹配')
@pytest.mark.smoke
def test_menu1(self):
logging.info('执行测试用例1')
assert 2 == 2
#@pytest.mark.repeat(2)
@pytest.mark.smoke
def test_menu2(self):
logging.info('执行测试用例2')
assert 1 == 1
def test_menu3(self):
logging.info('执行测试用例3')
assert 2 == 2
if __name__ == '__main__':
pytest.main()
test_work1.py
#encoding=utf-8
import pytest
#@pytest.mark.skip()
class TestWork:
@pytest.mark.smoke
def test_h(self,home_url):
print("用例:%s" % home_url)
@pytest.mark.skipif(8<24,reason='版本不匹配')
def test_work1(self):
assert 1 == 1
def test_work2(self):
assert 1 == 1
if __name__ == '__main__':
pytest.main()
执行命令
D:\project_development\api_pytest>pytest --html=./reports/test.html