pytest执行完后直接查看Allure的html报告
使用pytest时生成allure报告会觉得很麻烦,不像pytest-html插件一样,两步就能生成html报告。
allure的话就要这样
pip install pytest-html
pytest --html report/report.html
然后allure-results文件夹只有一堆xml文件,这时还需要安装allure-command-tools来解析生成html报告,
pip install allure-pytest
pytest --alluredir allure-results
如
> allure generate allure-results -o allure-report
之后就能在allure-report中发现html的测试报告了。
相比于pytest-html多了一个步骤,而且装的allure版本和pytest可能有匹配不上的问题,具体执行时会有一个找不到pytest-allure hook报错。
也可以利用pytest的hook函数,实现测试完成后自动生成并打开allure报告。
# conftest.py
def pytest_sessionfinish(session):
"""测试完成自动生成并打开allure报告"""
if session.config.getoption('allure_report_dir'):
try:
# 判断allure在环境路径中,通常意味着可以直接执行
if [i for i in os.getenv('path').split(';
') if os.path.exists(i) and 'allure' in os.listdir(i)]:
# 默认生成报告路径为: ./allure-report
os.system(f"allure generate -c {session.config.getoption('allure_report_dir')}")
os.system(f"allure open allure-report")
else:
logger.warn('allure不在环境变量中,无法直接生成html报告!')
except Exception as e:
logger.warn(e)
【pytest执行完后直接查看Allure的html报告】Allure报告功能强大太多了,比如错误分类,case的历史执行状态等。它的Jenkins插件倒是方便许多,自动执行了allure generate命令,配置一下每次生成报告的路径,就可以直接查看啦。
推荐阅读
- CVE-2020-16898|CVE-2020-16898 TCP/IP远程代码执行漏洞
- 图书集合完毕
- “不完美,才美”01(190410)
- 别墅庭院设计,不同的别墅庭院设计也给人视觉上完全不一样的!
- 2020-12(完成事项)
- 一些杂感(11)
- 摔跤吧爸爸
- 2020-06-07
- 字符串拼接成段落,换行符(\n)如何只执行n-1次
- 作业没有完成仍坚持要开家庭会议|作业没有完成仍坚持要开家庭会议 44