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")
4.生成测试报告
注意生成测试报告的命令必须在python测试用例执行的路径下执行才能够正确生成html格式的测试报告(如下:)
pytest -v --html=report/report.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。