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 @ 2022-08-03 16:55  cforcnb  阅读(2564)  评论(0)    收藏  举报