一.前言
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
测试报告
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/123165.html