pytest知识了解
pytest的基础知识了解:Python测试框架之pytest详解_lovedingd的博客-CSDN博客_pytest框架
(包含设置断点,pdb,获取最慢的10个用例的执行耗时)
pytest-pytest.main()运行测试用例,pytest参数: pytest-pytest.main()运行测试用例,pytest参数_小白爱吃饭的博客-CSDN博客
报错 usage: runAll.py [options] [file_or_dir] [file_or_dir] [...] ,是由于没有安装pytest-html
pytest 的使用
pytest中标签名的使用 : pytest之mark的使用 - 奔奔-武 - 博客园
Pytest装饰器 @pytest.mark.parametrize 的使用: Python Pytest装饰器@pytest.mark.parametrize详解_探索测试-CSDN博客_pytest.mark.parametrize
@pytest.mark.xfail : pytest xfail参数详解 - jescs - 博客园
@pytest.mark.skipif()
pytest 中的 fixture的使用
pytest 中的 fixture的使用(1): pytest进阶之fixture - linux超 - 博客园
pytest 的fixture的使用 (2):Pytest 使用简介 - 三只松鼠 - 博客园
将固件参数化:
注意:
1. 需要安装 pytest-html
2. 若出现了 report.html 运行的0 test, 则说明是文件的命名不对
pytest的命名规则:默认从当前目录中搜集测试用例,即在哪个目录下运行 pytest 命令,则中哪个目录中搜索
-符合命令规则 test_*.py 或者 *_test.py 的文件
-以 test_ 开头的函数名
-以 Test 开头的测试类(没有__init__函数)当中,以 test_ 开头的函数
3. @pytest.fixture() 以及 @pytest.mark.usefixture() 的用法
当function级别的 fixture 没有设置 autouse的时候, 执行完类级别的fixture,会直接执行 类中的函数
当function级别的 fixture 有设置 autouse的时候, 执行完类级别的fixture,会调用函数级别的fixture,再去执行类中的函数
(autouse: 如果为True,则fixture func将为所有测试用例激活可以看到它。如果为False(默认值),则需要显式激活fixture)
4. 上述的案例中,fixture函数 和 测试用例写在同一文件内,如果存在多个py 文件调用的话,则需要建一个 confest文件 ,test_xxx.py 测试文件中无需 import conftest, pytest 会自动搜索同级目录中的 conftest.py 文件
5. 需要获得返回参数的时候,不可使用 @pytest.mark.usefixtures(),需要直接传参 ,因为fixture中返回的数据默认在fixture名字里面存储
pyte st 的标签的使用 比如 @pytest.mark.demo :
标签不生效的处理方法:PytestUnknownMarkWarning: Unknown pytest.mark.wallet - is this a typo?..._weixin_30257433的博客-CSDN博客
Pytest:conftest.py在登录接口上的应用
Pytest:conftest.py在登录接口上的应用 - 简书
注意: 登录接口: headers 中需要传参qtoken的值 : 'qtoken':'VE9N35WLpFOYrEpOnrXC457xO8U2'
pytest 的 多进程运行cases 以及 重试运行cases
py test 在命令行(terminal)运行:
pytest test_skip.py #运行test_skip.py文件
pytest -v test_skip.py #查看详细的运行信息
pytest -m demo testCase/test_Search.py # 运行 被标记为demo的 用例,比如说有的用例未完成,则可标记为finished,unfinished ,来方便调试
pytest使用命令行来运行 测试用例:pytest教程之命令行方式运行用例_df0128的专栏-CSDN博客_pytest执行命令
pytest allure的教程
pytest allure的安装教程 Pytest+Allure生成自动化测试报告 - 一步一脚印丶 - 博客园
安装allure报错提示JAVA_HOME is set to an invalid directory解决办法: 安装allure报错提示JAVA_HOME is set to an invalid directory解决办法_textwj的博客-CSDN博客
对应的安装 java jdk的教程:JAVA_JDK下载与安装教程_weixin_42687361的博客-CSDN博客_javajdk安装步骤
安装jdk出现could not open 'D:\software\JAVA\lib\amd64\jvm.cfg' 的解决办法 win10安装jdk出现could not open 'D:\software\JAVA\lib\amd64\jvm.cfg'_lin1314yuan的博客-CSDN博客
allure 的用例描述使用 :allure(三十)--allure描述用例详细讲解 - 星空6 - 博客园
生成allure报告:
方法1:
if __name__ == '__main__':
pytest.main(['-s', '-q', '--alluredir', './allure'])
os.system('allure -c ./allure')
os.system('allure serve ./allure-report')
方法2:
pytest -n auto --alluredir=yourdir # -n auto:可以自动检测到系统的CPU核数 使用分布式运行用例 ; --alluredir=yourdir #只需添加 --alluredir 选项,并提供指向应存储结果的文件夹的路径 例如:pytest -n auto --alluredir .\report 或者 pytest -n auto --alluredir=report , report是你要放置的文件夹名称
allure serve report #report 是已生成json , txt 数据的文件夹
方法3:
pytest -sq --alluredir=report # 执行 pytest,指定 allure 结果目录为report文件夹
allure generate -c -o ./allure-report report #根据report文件夹中的文件, 生成 allure 的 html 报告 放在 allure-report文件夹下
allure open ./allure-report # 打开 allure 报告
清除之前生成的json,txt文件,生成新的文件
pytest test_2.py --alluredir=. /report --clean-alluredir #report为存放json,txt文件的文件夹 , 注意clean 后面接的是 - ,不是=
allure命令行 : Pytest 系列(27)- allure 命令行参数 - 小菠萝测试笔记 - 博客园
yaml文件:
yaml文件的使用 自动化项目配置或用例文件格式推荐--yaml - hyx20160514 - 博客园
yaml 校验器 YAML、YML在线编辑器(格式化校验)-BeJSON.com