首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Python单元测试expectedFailureIf

Python单元测试expectedFailureIf
EN

Stack Overflow用户
提问于 2018-06-09 02:07:09
回答 2查看 193关注 0票数 1

我可能是盲目的,在Python Unit Test FrameWork (Python2.7.10)中遗漏了一些东西。我试图将一个类标记为预期失败,但前提是该类在Windows上运行。其他平台工作正常。所以基本的概念是:

代码语言:javascript
复制
@unittest.expectedFailureIf(sys.platform.startswith("win"), "Windows Fails")
class MyTestCase(unittest.TestCase):
    # some class here
EN

回答 2

Stack Overflow用户

发布于 2018-06-09 02:27:26

来自文档**https://docs.python.org/2/library/unittest.html#skipping-tests-and-expected-failures

没有expectedFailureIf(),您可以使用expectedFailure()skipIf(sys.platform.startswith("win", "Windows Fails"))

票数 1
EN

Stack Overflow用户

发布于 2019-07-08 06:15:45

如前所述,Python2和Python3(如3.8版本)都没有内置此功能。

但是,通过在文件的顶部定义它,您可以很容易地自己创建它:

代码语言:javascript
复制
def expectedFailureIf(condition):
    """The test is marked as an expectedFailure if the condition is satisfied."""
    def wrapper(func):
        if condition:
            return unittest.expectedFailure(func)
        else:
            return func
    return wrapper

然后,您基本上可以按照您的建议执行操作(我没有添加原因,因为它不在现有的expectedFailure中):

代码语言:javascript
复制
class MyTestCase(unittest.TestCase):
    # some class here

    @expectedFailureIf(sys.platform.startswith("win"))
    def test_known_to_fail_on_windows_only(self):
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50766229

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档