目的:记录自己学习pytest中的一些知识点或者总结
问题:
1.安装pytest报错:pip安装第三方库报错SSL: CERTIFICATE_VERIFY_FAILED
原因:3.5以上的python需要验证SSL,解决方式在后面增加–trusted-host [url1] --trusted-host [url2] …
eg: pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org -U pytest
eg2:pip install xlrd -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
1.类需要以Test_开头,函数需要以test_开头,方法也需要以test_开头,否则不会被收集到
2.pytest可以兼容unittest
3.框架执行顺序:
module–>function–>class–>method
eg:
startup_module里面的内容——>执行非类的函数的startup——>执行类的函数的startup——>依次执行类中方法的startup
teardown_module里面的内容<——类的函数的teardown<——执行类的函数的teardown<——依次执行类中方法的teardown<——
4.常用断言方法
5.Mark的用法
1)跳过功能skip
@pytest.mark.skip or
@pytest.mark.skipif(“if 语句的写法,可叠加使用”)
以下是应用举例
2).xfail功能,某些已知失败的场景设置为失败
@pytest.mark.xfail
pytest学习小结
最新推荐文章于 2025-04-15 17:00:00 发布