北京推广网站,网站制作ppt,浏览器网站,免费网站建设行情命名规则 1)import pytest 测试文件名要以test_ 开头或 _test结尾 2#xff09;类名需要以Test开头#xff08;T#xff09;#xff0c;不能带有init方法 3#xff09;函数名以test_开头#xff08;t#xff09; 符合规则框架才能找到用例#xff0c;一条用例代表一条函… 命名规则 1)import pytest 测试文件名要以test_ 开头或 _test结尾 2类名需要以Test开头T不能带有init方法 3函数名以test_开头t 符合规则框架才能找到用例一条用例代表一条函数 pip install pytest 优点在内存中回收用例内容 提高运行效率不用再次调用方法 运行方式pytest.main([]) pytest.main([“-s”]) 里面可以输入内容list列表 pytest.main([“-s”,“-m run”]) -m remark的意思运行run标签的用例 跳过用例 在方法上面加pytest.mark.skip 运行 pytest.main([]) pytest.mark.run pytest.mark.modelName pytest.main([“-s”,“-m modelName”]) 报告生成pip install pytest-html使用allure会更好些也更简单 生成自带的modeName的用例报告 pytest.main([“-s”,“-m modeName”,“–htmlreport.html”]) 关键函数setup()预置条件 重置环境teardown() pytest.mark.baidu def setup_class(self) #类预置条件 ,需要将用例用类进行包裹 def teardown_class(self) #类重置环境 ,需要将用例用类进行包裹 setup和teardown操作 setup在测试函数或类之前执行完成准备工作例如数据库连接、测试数据、打开文件等 teardown在测试函数或类之后执行完成收尾工作例如断开数据库、回收内存资源等 传参 pytest.mark.parametrize(‘username,password’),[(‘your’,‘123456’,‘用户名不正确’)(‘you’,‘123456’,‘ok’)] 思路 断言assert 封装 数据与业务抽离优化 数据写另外文件 if __name__ __main__:pytest.main([-sv,test_py.py])