3
0
热心网友
#首先使用 pip 安装 pytestpip install pytest pip install pytest-html #原生态报告模板pip show pytest #查看 pytest 是否安装成功
@pytest.mark.parametrize( "x,y,z", [(1,2,3),(2,3,4)] ) #列表套列表/列表套元组均可 def test1(x,y,z): assert x+y == z
调用fixture的三种方法
1 #1、函数或类里面方法直接传fixture的函数参数名称 2 @pytest.fixture() 3 def test1(): 4 print('\n开始执行function') 5 6 def test_a(test1): 7 print('---用例a执行---') 8 9 #2、使用装饰器@pytest.mark.usefixtures()修饰需要运行的用例 10 @pytest.fixture() 11 def test1(): 12 print('\n开始执行function') 13 @pytest.mark.usefixtures('test1') 14 def test_a(): 15 print('---用例a执行---') 16 17 #3、叠加usefixtures 18 #如果一个方法或者一个class用例想要同时调用多个fixture,可以使用@pytest.mark.usefixture()进行叠加。注意叠加顺序,先执行的放底层,后执行的放上层。 19 import pytest 20 21 @pytest.fixture() 22 def test1(): 23 print('\n开始执行function') 24 25 @pytest.mark.usefixtures('test1') 26 def test_a(): 27 print('---用例a执行---') 28 29 @pytest.fixture() 30 def test1(): 31 print('\n开始执行function1') 32 33 @pytest.fixture() 34 def test2(): 35 print('\n开始执行function2') 36 37 @pytest.mark.usefixtures('test1') 38 @pytest.mark.usefixtures('test2') 39 def test_a(): 40 print('---用例a执行---')
#pytest.main()启动Pytest测试运行器,main() 函数如果不带任何参数,会自动查找和执行当前路径及其子目录中所有符合Pytest命名规范的所有测试文件(通常是文件名以 test_ 开头)。 #常用参数:
#示例
Login类: 登录方法 loginShop类: 列出方法 shop_list 更新方法 shop_update
-m <标记>
@pytest.mark
and
or
如:pytest.main(['-m', 'smoke']) # 执行标记为smoke的用例
-k <表达式>
报告添加附件
使用道具 舉報
本版積分規則 發表回覆 回帖並轉播 回帖後跳轉到最後一頁
相关侵权、举报、投诉及建议等,请发 E-mail:qiongdian@foxmail.com
Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.