zoukankan      html  css  js  c++  java
  • pytest标记测试用例为预期失败(@pytest.mark.xfail)

      我们平时在写测试用例的过程中,有时会遇到“已知由于某些原因,某些场景是有问题的,或者是功能暂时没有实现”这种情况,那么测试用例执行的时候我们就知道这个测试用例会失败,也就是预期失败,这个时候我们就可以使用@pytest.mark.xfail装饰器来标记测试用例为预期失败函数。

    @pytest.mark.xfail使用

    标记测试函数为失败函数
    
     方法:
         xfail(condition=None, reason=None, raises=None, run=True, strict=False)
    
     常用参数:
         condition:预期失败的条件,必传参数
         reason:失败的原因,必传参数
    
     使用方法:
         @pytest.mark.xfail(condition, reason="xx")

    举例:

    # file_name: test_xfail.py
    
    
    import pytest
    
    
    class Test_C:
    
        def test_a(self):
            print('
    ------------------> test_a has ran')
            assert 1
    
        @pytest.mark.xfail(condition=2 > 1, reason='标记为预期失败')
        def test_b(self):
            print('------------------> test_b has ran')
            assert 0
    
    
    if __name__ == '__main__':
        pytest.main(['-s', 'test_xfail.py'])

    运行结果:

     x表示被@pytest.mark.xfail标记失败了。

  • 相关阅读:
    Spring MVC 体系结构和处理请求控制器
    Spring配置补充
    MyBatis与Spring的整合
    Ioc和AOP使用扩展
    JS 节流
    JS写返回上一级
    iframe父页面获取子页面的高度
    博客编写计划
    正则表达式
    实用 SQL 命令
  • 原文地址:https://www.cnblogs.com/lwjnicole/p/14431824.html
Copyright © 2011-2022 走看看