我可能是盲目的,在Python Unit Test FrameWork (Python2.7.10)中遗漏了一些东西。我试图将一个类标记为预期失败,但前提是该类在Windows上运行。其他平台工作正常。所以基本的概念是:
@unittest.expectedFailureIf(sys.platform.startswith("win"), "Windows Fails")
class MyTestCase(unittest.TestCase):
# some class here
发布于 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"))
发布于 2019-07-08 06:15:45
如前所述,Python2和Python3(如3.8版本)都没有内置此功能。
但是,通过在文件的顶部定义它,您可以很容易地自己创建它:
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中):
class MyTestCase(unittest.TestCase):
# some class here
@expectedFailureIf(sys.platform.startswith("win"))
def test_known_to_fail_on_windows_only(self):
https://stackoverflow.com/questions/50766229
复制相似问题