首页 > 其他分享 >pytest.main( )参数大全

pytest.main( )参数大全

时间:2022-08-18 19:15:01浏览次数:60  
标签:slow py 用例 pytest test main 大全

一、常用参数大全

1、-s:输出打印(print/logging)信息;

2、-v:显示具体丰富的信息;

3、-k:执行用例名称中包含某字符段的用例。

  举个 pytest.main(['-k','taiwan']) #执行测试用例名称包含taiwan的用例;

    pytest.main(['-k',"One",'./testOne/test_one.py'])#匹配test_one.py模块下包含One的用例

4、-q:输出简化信息,不输出环境信息;

5、-x:只要出现测试用例失败,后面的用例不再执行;

6、--junit-xml:设置junit xml测试报告。  

  举个  pytest.mian(['--junit-xml=./report/junit_report.xml']);

7、--maxfail:设置失败几次就结束测试。

  举个  pytest.main(['--maxfail=3']) #三次失败后结束所有测试;     

          
 二、选择执行用例

pytest.main(['test_suit.py::test_case_name']);#精确选择

pytest.main(['./']) #运行./目录下所有(test_*.py和*_test.py);

pytest.main(['./testOne']) #运行./testOne目录下用例;

pytest.main(['./testOne/test_one.py']) #运行指定模块;

pytest.main(['-k','order','./testOne/test_one.py::TestOne']) #匹配TestOne类中包含order的用例

 
三、添加装饰器

1)首先配置文件.ini文件,添加:
 [pytest]
 markers =
     标签名: 描述信息
     slow: mark tests as slow
     smoke: mark tests as smoke            
 2)在测试用例添加标记装饰器@pytest.mark.slow(slow是标签名)
 3)main函数写作:pytest.main(['-m', 'slow'])



很多时候,我们在听别人讲话的时候,其实总是急于表达自己的观点,迫切的想要表达出来好得到对方的认可。而有时候说出口的话不经大脑思考,脱口而出,事后便会发现那句话说得有问题,在无意间还是伤害到了对方的面子,这是隐形的暴力沟通。好好说话看似很简单,其实很难,这是一门学问,还需精心修炼!

标签:slow,py,用例,pytest,test,main,大全
From: https://www.cnblogs.com/lzcnblogs/p/16599655.html

相关文章