def test_old_testresult(self):
class Test(unittest2.TestCase):
def testSkip(self):
self.skipTest('foobar')
@unittest2.expectedFailure
def testExpectedFail(self):
raise TypeError
@unittest2.expectedFailure
def testUnexpectedSuccess(self):
pass
for test_name, should_pass in (('testSkip', True),
('testExpectedFail', True),
('testUnexpectedSuccess', False)):
test = Test(test_name)
self.assertOldResultWarning(test, int(not should_pass))
python类expectedFailure()的实例源码
_test_unittest2_with.py 文件源码
项目:devsecops-example-helloworld
作者: boozallen
项目源码
文件源码
阅读 24
收藏 0
点赞 0
评论 0
def test_expected_failure_subtests(self):
# A failure in any subtest counts as the expected failure of the
# whole test.
class Foo(unittest.TestCase):
@unittest.expectedFailure
def test_die(self):
with self.subTest():
# This one succeeds
pass
with self.subTest():
self.fail("help me!")
with self.subTest():
# This one doesn't get executed
self.fail("shouldn't come here")
events = []
result = LoggingResult(events)
test = Foo("test_die")
test.run(result)
self.assertEqual(events,
['startTest', 'addSubTestSuccess',
'addExpectedFailure', 'stopTest'])
self.assertEqual(len(result.expectedFailures), 1)
self.assertIs(result.expectedFailures[0][0], test)
self.assertTrue(result.wasSuccessful())
def test_unexpected_success_subtests(self):
# Success in all subtests counts as the unexpected success of
# the whole test.
class Foo(unittest.TestCase):
@unittest.expectedFailure
def test_die(self):
with self.subTest():
# This one succeeds
pass
with self.subTest():
# So does this one
pass
events = []
result = LoggingResult(events)
test = Foo("test_die")
test.run(result)
self.assertEqual(events,
['startTest',
'addSubTestSuccess', 'addSubTestSuccess',
'addUnexpectedSuccess', 'stopTest'])
self.assertFalse(result.failures)
self.assertEqual(result.unexpectedSuccesses, [test])
self.assertFalse(result.wasSuccessful())
def test_expected_failure(self):
class Foo(unittest2.TestCase):
@unittest2.expectedFailure
def test_die(self):
self.fail("help me!")
events = []
result = LoggingResult(events)
test = Foo("test_die")
test.run(result)
self.assertEqual(events,
['startTest', 'addExpectedFailure', 'stopTest'])
self.assertEqual(result.expectedFailures[0][0], test)
self.assertTrue(result.wasSuccessful())
def test_unexpected_success(self):
class Foo(unittest2.TestCase):
@unittest2.expectedFailure
def test_die(self):
pass
events = []
result = LoggingResult(events)
test = Foo("test_die")
test.run(result)
self.assertEqual(events,
['startTest', 'addUnexpectedSuccess', 'stopTest'])
self.assertFalse(result.failures)
self.assertEqual(result.unexpectedSuccesses, [test])
self.assertFalse(result.wasSuccessful())
def compile_and_run_file_failing_test(*a, **k):
"""Turn a test to a failing test"""
_class = compile_and_run_file_test(*a, **k)
class FailingTest(_class):
"""Failing test"""
@unittest.expectedFailure
def runTest(self):
return super(FailingTest, self).runTest()
return FailingTest
def expectedFailurePY3(func):
if not PY3:
return func
return unittest.expectedFailure(func)
def expectedFailurePY26(func):
if not PY26:
return func
return unittest.expectedFailure(func)
def expectedFailurePY27(func):
if not PY27:
return func
return unittest.expectedFailure(func)
def expectedFailurePY2(func):
if not PY2:
return func
return unittest.expectedFailure(func)
# Renamed in Py3.3:
def anticipate_failure(condition):
"""Decorator to mark a test that is known to be broken in some cases
Any use of this decorator should have a comment identifying the
associated tracker issue.
"""
if condition:
return unittest.expectedFailure
return lambda f: f
def expectedFailurePY3(func):
if not PY3:
return func
return unittest.expectedFailure(func)
def expectedFailurePY26(func):
if not PY26:
return func
return unittest.expectedFailure(func)
def expectedFailurePY27(func):
if not PY27:
return func
return unittest.expectedFailure(func)
def expectedFailurePY2(func):
if not PY2:
return func
return unittest.expectedFailure(func)
# Renamed in Py3.3:
def anticipate_failure(condition):
"""Decorator to mark a test that is known to be broken in some cases
Any use of this decorator should have a comment identifying the
associated tracker issue.
"""
if condition:
return unittest.expectedFailure
return lambda f: f
def expectedFailurePY3(func):
if not PY3:
return func
return unittest.expectedFailure(func)
def expectedFailurePY26(func):
if not PY26:
return func
return unittest.expectedFailure(func)
def expectedFailurePY27(func):
if not PY27:
return func
return unittest.expectedFailure(func)
def expectedFailurePY2(func):
if not PY2:
return func
return unittest.expectedFailure(func)
# Renamed in Py3.3:
def anticipate_failure(condition):
"""Decorator to mark a test that is known to be broken in some cases
Any use of this decorator should have a comment identifying the
associated tracker issue.
"""
if condition:
return unittest.expectedFailure
return lambda f: f
def expectedFailurePY3(func):
if not PY3:
return func
return unittest.expectedFailure(func)
def expectedFailurePY26(func):
if not PY26:
return func
return unittest.expectedFailure(func)
def expectedFailurePY2(func):
if not PY2:
return func
return unittest.expectedFailure(func)
# Renamed in Py3.3:
def anticipate_failure(condition):
"""Decorator to mark a test that is known to be broken in some cases
Any use of this decorator should have a comment identifying the
associated tracker issue.
"""
if condition:
return unittest.expectedFailure
return lambda f: f
def expectedFailurePY3(func):
if not PY3:
return func
return unittest.expectedFailure(func)
def expectedFailurePY26(func):
if not PY26:
return func
return unittest.expectedFailure(func)
def expectedFailurePY2(func):
if not PY2:
return func
return unittest.expectedFailure(func)
# Renamed in Py3.3:
def anticipate_failure(condition):
"""Decorator to mark a test that is known to be broken in some cases
Any use of this decorator should have a comment identifying the
associated tracker issue.
"""
if condition:
return unittest.expectedFailure
return lambda f: f
def expectedFailurePY3(func):
if not PY3:
return func
return unittest.expectedFailure(func)