I may be blind and missing something in the Python Unit Test FrameWork (Python 2.7.10). I'm trying to mark a class as an expected failure but only if the class is run on Windows. Other platforms work correctly. So the basic concept would be:
@unittest.expectedFailureIf(sys.platform.startswith("win"), "Windows Fails")
class MyTestCase(unittest.TestCase):
# some class here
From the documentation ** https://docs.python.org/2/library/unittest.html#skipping-tests-and-expected-failures
There is no expectedFailureIf()
, you can use expectedFailure()
or skipIf(sys.platform.startswith("win", "Windows Fails"))
As mentioned, neither Python 2 nor Python 3 (as at 3.8) have this built in.
You can pretty easily create this yourself, however, by defining it at the top of your file:
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
Then you can do essentially as you suggest (I have not added reason, as that isn't in the existing expectedFailure):
class MyTestCase(unittest.TestCase):
# some class here
@expectedFailureIf(sys.platform.startswith("win"))
def test_known_to_fail_on_windows_only(self):
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.