目录
1.allure测试报告
2.生成resultlog文件
3.生成JunitXML文件
4.生成测试用例的URL
5.生成html测试报告
总结:
先前博客有介绍pytest测试框架的安装及使用,现在来聊聊pytest可以生成哪些测试报告
#!/usr/bin/python# -*- coding: UTF-8 -*-"""@author:chenshifeng@file:test_report.py@time:2021/01/27"""class TestReport: def test_one(self): x = "shifeng" assert "feng" in x def test_two(self): x = "hello" assert x == "hi"
执行命令:
pytest test_report.py --resultlog=./resultlog.txt
指定当前路径下生成resultlog.txt文件,打开文件,内容如下:
. reportdemo/test_report.py::TestReport::test_oneF reportdemo/test_report.py::TestReport::test_two self = def test_two(self): x = "hello" > assert x == "hi" E AssertionError: assert 'hello' == 'hi' E - hi E + hello test_report.py:16: AssertionError
执行命令:
pytest test_report.py --junitxml=./resultlog.xml
同样指定在当前目录下生成resultlog.xml文件,打开文件内容如下:
self = <test_report.TestReport object at 0x7fa152b97790> def test_two(self): x = "hello" > assert x == "hi" E AssertionError: assert 'hello' == 'hi' E - hi E + hello test_report.py:16: AssertionError
创建这样的XML文件有有什么用? 主要是为了方便Jenkin或其它的持续集成工具读取。
执行命令:
pytest test_report.py --pastebin=all
复制打印结果最后生成的session-log测试报告链接到浏览器:
pytest test_class.py --pastebin=failed
通过pip安装pytest-html
pip install pytest-html
在代码文件的当前目录下执行命令
pytest test_report.py --html=./report.html
指定在当前目录下生成report.html文件,打开测试文件:
感谢每一个认真阅读我文章的人!!!
我个人整理了我这几年软件测试生涯整理的一些技术资料,包含:电子书,简历模块,各种工作模板,面试宝典,自学项目等。欢迎大家评论区留言333免费领取,千万不要错过哦。