pytest-自动生成测试报告

1.windows安装pytest插件:

pip install pytest
pip install pytest-html
pip install pytest-rerunfailures
pip install allure-pytest

2.编写测试用例执行代码

import pytest

# 定义前置处理,设置autouse=True后,pytest会自动在测试方法调用,不需要测试方法声明要使用该fixture
# 加一个前置 是True的话使用的时候不用传参数,可以直接使用,并且每次都会执行
@pytest.fixture(autouse=True)
def beforeEach():
    print("我是beforeEach fixture")

# 定义前置处理,需要测试方式声明该fixture才会在测试方法之前调用
# 不需要测试方法声明要使用该fixture
@pytest.fixture()
def before():
    print("我是before fixture")


'''
    定义后置处理器after,
'''
@pytest.fixture()
def after():
    yield
    print("我是after fixture")

# 参数传进去了才会被使用
# 使用参数方式,声明使用上面定义的before fixture
def test_01(before):
    print("我是test001")


@pytest.mark.usefixtures('before')
def test_02():
    print("我是test002")

def test_03(before,after):
    print("我是test03")

3.在DOS窗口下执行生成测试报告代码

 

4.生成测试报告

  注意生成测试报告的命令必须在python测试用例执行的路径下执行才能够正确生成html格式的测试报告(如下:)

pytest -v --html=report/report.html

相关文章

目录1、前言2、mark的使用(一)注册自定义标记(二)在测试...
用例执行状态用例执行完成后,每条用例都有自己的状态,常见...
什么是conftest.py可以理解成一个专门存放fixture的配置文件...
前言pytest默认执行用例是根据项目下的文件名称按ascii码去收...
前言:什么是元数据?元数据是关于数据的描述,存储着关于数...