pytest常用运行用例快捷命令学习

pytest作为自动化测试中常用的库,学会一些常用快捷名令更能结合用例去使用 

import pytest




class Test_l():




    def test_one(self):
        print('hello')
        assert 1==1




    def test_two(self):
        assert 1==3


    def test_three(self):
        assert 5==5




if __name__ == '__main__':
    '''
    —-ff 先运行失败的用例,在运行所有用例
    -n auto 多线程运行
    -reruns 失败重试次数
    --lf仅运行上次失败的测试用例
    -x   遇到失败就停止运行
    -maxfail=x  x等于失败的用例数,超过这个数量就停止运行
    -k xx 模糊匹配def中包含xx的方法
    --collect-only 收集可以运行的测试用例
    -m 执行标记用例
    -vs 一般放在一起使用,控制台打印测试用例运行情况更详细的输出
    '''


    pytest.main(['-vs','test_run.py','--lf'])    #--lf仅运行失败的用例,在运行所有的用例

    pytest.main(['-vs','test_run.py','--ff'])    #--ff先运行失败的用例,在执行其他用例


    pytest.main(['-vs', 'test_run.py', '-k','one'])  # -k xx 模糊匹配def中包含xx的方法

    pytest.main(['-vs', 'test_run.py', '--collect-only'])  # --collect-only 收集可以运行的·测试用例

pytest.ini文件 通俗将就是将用例执行的代码,写在pytest.ini文件中使代码看着更加简洁

pytest.ini文件一般放在项目的根目录下,pytest.mian()运行时会自动查找pytest.ini文件的数据,然后去运行文件中配置中的数据

1、look look 文件

#文件必须以[pytest]开头
[pytest]

#测试用例存放的路径
testpaths=·/testcase 测试文件路径

#测试用例对应的py文件名,'test_demo_*代表的意思:所有包含test_demo_的py文件'
python_files = test_demo_*    文件

#测试用例中对应的测试类的名称
python_classes = Test*     类

#测试用例中对应测试类下的测试方法
python_functions = test_one 方法

#addopts 的意思 = pytest.main(['-vs','-reruns=2','xxxx.py'])里的'-vs','-reruns=2'
addopts=-vs -rerun=2

2、如何调用pytest.ini文件

import pytest




class Test_l():




    def test_one(self):
        print('hello')
        assert 1==1




    def test_two(self):
        assert 1==3


    def test_three(self):
        assert 5==5




if __name__ == '__main__':
   pytest.main()

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值