Pytest-跳过测试函数

前置条件:
        1.文件路径:
            - Test_App
            - - test_abc.py
            - - pytest.ini
        2.pyetst.ini配置文件内容:
            [pytest]
            # 命令行参数
            addopts = -s
            # 搜索文件名
            python_files = test_*.py
            # 搜索的类名
            python_classes = Test_*
            # 搜索的函数名
            python_functions = test_*
方法:
        skipif(condition, reason=None)
    参数:
        condition:跳过的条件,必传参数
        reason:标注原因,必传参数
    使用方法:
        @pytest.mark.skipif(condition, reason="xxx")
    示例:
        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 # 跳过函数

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值