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  # 跳过函数```"""
posted @ 2021-11-23 13:29  暄总-tester  阅读(87)  评论(0)    收藏  举报