pytest中使用skip跳过某个函数

目录

1-- 如果我们在pytets中不想让某些函数执行

2-- 跳过某些我们不想执行的函数


如果我们在pytets中不想让某些函数执行

  1. 因为这些函数执行会因为某些原因执行错误
    1. 可能因为,版本不兼容
    2. 机型原因等
  2. 想跳过当前执行
    1. 可以通过
      1.

      复制代码
      @pytest.mark.skip(reason ="当前版本不兼容")
      1. @pytest.mark.skip(reason = "原因") 直接跳过

跳过某些我们不想执行的函数

  1. 复制代码
    import pytest
    
    
    class TestRerunFailures:
    
        def test_demo_001(self):
            print("---------test_demo_001--------")
            print("success")
            assert True
    
        def test_demo_002(self):
            print("---------test_demo_002--------")
            print("success")
            assert True
    
        
       def test_demo_003(self):
            print("---------test_demo_003--------")
            print("fail")
            assert False
        
    def test_demo_004(self):        print("---------test_demo_004--------")
            print("fail")
            assert False
    
        def test_demo_005(self):
            print("---------test_demo_005--------")
            print("success")
            assert True
  2. 我们不想执行

    1. def test_demo_003(self)
    2. def test_demo_004(self)
  3. 使用
    1.

    复制代码
    @pytest.mark.skip(reason="当前版本不兼容")
    def test_demo_003(self):
        print("---------test_demo_003--------")
        print("fail")
        assert False
    复制代码
    1. 复制代码
      @pytest.mark.skip(reason="测试设备不支持")
      def test_demo_004(self):
          print("---------test_demo_004--------")
          print("fail")
          assert False
      复制代码
    2. 标记完之后的运行结果

    3. 在执行已经标记过的函数已经跳过了

  4. 也可以使用 skipif进行跳过
    1.

    复制代码
    @pytest.mark.skipif(condition=False, reason="fail")
    def test_demo_002(self):
        print("---------test_demo_002--------")
        print("success")
        assert True
    复制代码
    @pytest.mark.skipif(condition=False, reason="fail")
    1. 这个可以针对condition条件机型判断
相关推荐
思茂信息36 分钟前
CST软件对Customer Success OPPO手机电源适配器EMC仿真
开发语言·嵌入式硬件·matlab·3d·智能手机·cst
缺点内向2 小时前
如何在 C# 中将 Excel 工作表拆分为多个窗格
开发语言·c#·.net·excel
少废话h3 小时前
解决Flink中ApacheCommonsCLI版本冲突
开发语言·python·pycharm
serve the people3 小时前
TensorFlow 图执行(tf.function)的 “非严格执行(Non-strict Execution)” 特性
人工智能·python·tensorflow
天命码喽c3 小时前
GraphRAG-2.7.0整合Milvus-2.5.1
开发语言·python·milvus·graphrag
后端小张3 小时前
【JAVA进阶】Spring Boot 核心知识点之自动配置:原理与实战
java·开发语言·spring boot·后端·spring·spring cloud·自动配置
吴佳浩5 小时前
LangChain 深入
人工智能·python·langchain
网安-轩逸8 小时前
回归测试原则:确保软件质量的基石
自动化测试·软件测试·python
卓码软件测评8 小时前
第三方CNAS软件测试报告【Gatling和云原生环境集成_在Kubernetes和Docker中部署与执行测试】
测试工具·自动化·测试用例·负载均衡·压力测试
Mr_Xuhhh8 小时前
YAML相关
开发语言·python