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条件机型判断
相关推荐
HoneyMoose1 分钟前
Postman 测试 API 如何上传文件
测试工具·postman
2301_764441336 分钟前
LISA时空跃迁分析,地理时空分析
数据结构·python·算法
014-code27 分钟前
订单超时取消与库存回滚的完整实现(延迟任务 + 状态机)
java·开发语言
lly20240643 分钟前
组合模式(Composite Pattern)
开发语言
游乐码1 小时前
c#泛型约束
开发语言·c#
Dontla1 小时前
go语言Windows安装教程(安装go安装Golang安装)(GOPATH、Go Modules)
开发语言·windows·golang
chushiyunen1 小时前
python rest请求、requests
开发语言·python
cTz6FE7gA1 小时前
Python异步编程:从协程到Asyncio的底层揭秘
python
铁东博客1 小时前
Go实现周易大衍筮法三变取爻
开发语言·后端·golang
baidu_huihui1 小时前
在 CentOS 9 上安装 pip(Python 的包管理工具)
开发语言·python·pip