跳过预期失败

xfail的Python项目详细描述


https://img.shields.io/pypi/v/xfail.svghttps://img.shields.io/pypi/pyversions/xfail.svghttps://img.shields.io/travis/miyakogi/xfail.py.svghttps://codecov.io/github/miyakogi/xfail.py/coverage.svg?branch=master

xfail提供了一个decorator函数xfail来跳过预期的异常。 类似于unittest.skipIf,但是xfail可以指定应该是哪个异常 跳过,并在修饰函数意外传递时引发(仅当 strictTrue

安装

支持的python版本有:2.7、3.4、3.5、3.6

可以通过pip从PyPI安装:

pip install xfail

用法

xfail decorator

xfail接受两个参数,exceptionsstrict

第一个参数(exceptions)应该是要跳过的异常类(例如。 ExceptionAssertionError等等)。如果你想跳过多个 异常,使用它们的元组,例如,@xfail((AssertionError, ValueError))

第二个参数strict应该是布尔值。如果strictFalse (默认)并意外传递,引发unittest.SkipTest异常, 这将标志着测试被跳过。这个例子与函数非常相似 由uniteest.skip函数修饰,测试将被计为 跳过。

If it is ^{tt4}$ and the decorated function did not raise (any of) the expected exception(s), ^{tt18}$ exception would be raised. In this case, the test will be counted as fail.
fromxfailimportxfail@xfail(IndexError)defget(l,index):returnl[index]l=[1,2,3]get(4)# no error

还支持多个例外:

@xfail((IndexError,ValueError))defa():'''This function passes IndexError and ValueError
    ...

在测试脚本中,类似于unittest.TestCase.assertRaises

fromunittestimportTestCasefromxfailimportxfailclassMyTest(TestCase):deftest_1(self):@xfail(AssertionError)defshould_raise_error():assertFalsea()# test passesdeftest_2(self):@xfail(AssertionError,strict=True)defshould_raise_error():assertTruea()# test failes, since this function should raise AssertionError# Can be used for test function@xfail(AssertionError,strict=True)deftest_3(self)assertFalse# This test will fail@xfail(AssertionError,strict=True)deftest_3(self)assertTrue

有关更多示例,请参见test_xfail.py

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java应该考虑使用DTO来代替Spring控制器层吗?   java为什么要将Maven与Git结合起来?   java试图将CSV转换为XLSX,但使用了错误的逗号拆分列   mysql Spring 3+Hibernate:java。sql。BatchUpdateException:无法添加或更新子行(ManyToMany)   java基本字符串反转器   java无法使用RestControllerAdvice为身份验证失败生成自定义错误消息   java当只允许SQLException时,如何抛出EOFEException?   java如何创建播放模块?   Android中匿名类的java实例化异常问题   java两个停靠组件,其中第二个组件填充剩余空间   java如何在按钮延迟时启用它   Java中正在运行的应用程序中的后台进程   java我正试图从一个字符串打印出这个字符输出   如何使用java socket通过两个不同的wifi连接两台电脑?   javaapachecamel:如何将分层数据从数据库转换为pojo   java Webrtc:OniconConnectionChange和onConnectionChange之间有什么区别   java如何重写已经创建的JTable方法   爪哇扫雷机堆垛机   雅加达ee Java ee EJB 3.0 Glassfish