Issue #16997: unittest.TestCase now provides a subTest() context manager to procedurally generate, in an easy way, small test instances.

This commit is contained in:
Antoine Pitrou 2013-03-20 20:16:47 +01:00
parent a612176c9c
commit c9b3ef2df0
10 changed files with 540 additions and 106 deletions

View file

@ -5,6 +5,7 @@ import pickle
import subprocess
import unittest
from unittest.case import _Outcome
from .support import LoggingResult, ResultWithNoStartTestRunStopTestRun
@ -42,12 +43,8 @@ class TestCleanUp(unittest.TestCase):
def testNothing(self):
pass
class MockOutcome(object):
success = True
errors = []
test = TestableTest('testNothing')
test._outcomeForDoCleanups = MockOutcome
outcome = test._outcome = _Outcome()
exc1 = Exception('foo')
exc2 = Exception('bar')
@ -61,9 +58,10 @@ class TestCleanUp(unittest.TestCase):
test.addCleanup(cleanup2)
self.assertFalse(test.doCleanups())
self.assertFalse(MockOutcome.success)
self.assertFalse(outcome.success)
(Type1, instance1, _), (Type2, instance2, _) = reversed(MockOutcome.errors)
((_, (Type1, instance1, _)),
(_, (Type2, instance2, _))) = reversed(outcome.errors)
self.assertEqual((Type1, instance1), (Exception, exc1))
self.assertEqual((Type2, instance2), (Exception, exc2))