其他分享
首页 > 其他分享> > Pytest13--跳过测试函数

Pytest13--跳过测试函数

作者:互联网

跳过测试函数

   根据特定的条件,不执行标识的测试函数.
     方法:
         skipif(condition, reason=None)
     参数:
         condition:跳过的条件,必传参数
         reason:标注原因,必传参数
     使用方法:
         @pytest.mark.skipif(condition, reason="xxx")

编写test_demo01.py

import pytest
class Test_ABC:
    def setup_class(self):
        print("------->setup_class")
    def teardown_class(self):
        print("------->teardown_class")
    def test_a(self):
        print("------->test_a")
        assert 1
    @pytest.mark.skipif(condition=2 > 1, reason="跳过该函数")  # 跳过测试函数test_b
    def test_b(self):
        print("------->test_b")
        assert 0
"""执行结果:
test_abc.py
------->setup_class
------->test_a  # 只执行了函数test_a
.
------->teardown_class
s  # 跳过函数```"""

标签:--,self,-------,Pytest13,测试函数,test,跳过,class
来源: https://www.cnblogs.com/sean-test/p/15592793.html