pytest+pytest-testreport 生成测试报告

一、安装

     (1)安装pytest

                

pip3 install pytest

 

     (2)安装 pytest-testreport 

                

pip3 install pytest-testreport

 

二、在项目 test_pytest_report中生成两个文件:pytest_1.py、pytest.ini

      (1) pytest_1.py

复制代码
import os
import pytest

def func(x):
    return x + 1

def test_a():
    assert func(2) == 5

def test_b():
    assert func(2) == 3


# 测试报告模板 pytest-testreport 的一些配置
pytest.main(['--report=_report.html',
             '--title=边缘组件自动化验收报告',
             '--tester=测试员',
             '--desc=报告描述信息',
             '--template=1'])


'''
说明:
由于在pytest.ini文件中已设置 python_files = pytest_1.py,故只需要直接在 Terminal中输入pytest 就会自动只执行pytest_1.py这个文件
执行完成后,在reports文件中刷新一下,就可找到最新生成的测试报告
'''
复制代码

      (2) pytest.ini

复制代码
# pytest.ini
[pytest]

addopts=-v -s

# testpaths = testcase

python_files = pytest_1.py

# python_classes = Test_*

# python_functions = test_*
复制代码

 

 

 

 

三、由于在pytest.ini文件中已设置 python_files = pytest_1.py,故只需要直接在 Terminal中输入pytest 就会自动只执行pytest_1.py这个文件

        执行完成后,在reports文件中刷新一下,就可找到最新生成的测试报告。

        浏览器中显示如下:

 

posted @   cforcnb  阅读(2468)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
点击右上角即可分享
微信分享提示