码迷,mamicode.com
首页 > 其他好文 > 详细

skip 和 skipif的用法

时间:2020-12-22 12:26:32      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:process   --   false   start   原因   ===   rgba   summary   代码   

skip:无条件跳过

@pytest.mark.skip

 1 import pytest
 2  
 3 class Test_One():
 4     @pytest.mark.skip
 5     def test_01(self):
 6         print("===========> test_01")
 7  
 8     def test_02(self):
 9         print("===========> test_02")
10  
11 if __name__ == "__main__":
12     pytest.main(["-rs", "test_three.py::Test_one"])

可以看到执行结果第8行中,unconditional skip 表示无条件跳过

 1 F:\Python3.6.5\python.exe E:/xxx/test_three.py
 2 ============================= test session starts =============================
 3 platform win32 -- Python 3.6.5, pytest-6.1.1, py-1.9.0, pluggy-0.13.1
 4 rootdir: E:\xxx, configfile: pytest.ini
 5 collected 2 items
 6 test_three.py s.                                                         [100%]
 7 =========================== short test summary info ===========================
 8 SKIPPED [1] test_three.py:9: unconditional skip
 9 ======================== 1 passed, 1 skipped in 0.51s =========================
10 Process finished with exit code 0

 

skipif:有条件跳过

@pytest.mark.skipif(condition=跳过的条件, reason=跳过的原因))

 1 # <------- test_three.py ------->
 2 #!/usr/bin/python3
 3 # coding=utf-8
 4 # Author: 文
 5  
 6 import pytest
 7  
 8 class Test_One():
 9     @pytest.mark.skipif(condition=1<2, reason="参数condition为True,跳过测试")
10     def test_03(self):
11         print("===========> test_03")
12  
13     @pytest.mark.skipif(condition=1>2, reason="参数condition为False,不跳过测试")
14     def test_04(self):
15         print("===========> test_04")
16  
17 if __name__ == "__main__":
18     pytest.main(["-rs", "test_three.py::Test_One"])

上面代码第9行,1<2 为True,跳过该条用例

执行结果第8行,展示了reason参数对应的值

第13行,1>2 为False,则不跳过该用例

 1 F:\Python3.6.5\python.exe E:/xxx/test_three.py
 2 ============================= test session starts =============================
 3 platform win32 -- Python 3.6.5, pytest-6.1.1, py-1.9.0, pluggy-0.13.1
 4 rootdir: E:\xxx, configfile: pytest.ini
 5 collected 2 items
 6 test_three.py s.                                                         [100%]
 7 =========================== short test summary info ===========================
 8 SKIPPED [1] test_three.py:9: 参数condition为True,跳过测试
 9 ======================== 1 passed, 1 skipped in 1.13s =========================
10 Process finished with exit code 0

 

skip 和 skipif的用法

标签:process   --   false   start   原因   ===   rgba   summary   代码   

原文地址:https://www.cnblogs.com/zcxzcx/p/14150398.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!