Back to index

python3.2  3.2.2
Public Member Functions
unittest.test.test_runner.TestCleanUp Class Reference

List of all members.

Public Member Functions

def testCleanUp
def testCleanUpWithErrors
def testCleanupInRun
def testTestCaseDebugExecutesCleanups

Detailed Description

Definition at line 12 of file test_runner.py.


Member Function Documentation

Definition at line 14 of file test_runner.py.

00014 
00015     def testCleanUp(self):
00016         class TestableTest(unittest.TestCase):
00017             def testNothing(self):
00018                 pass
00019 
00020         test = TestableTest('testNothing')
00021         self.assertEqual(test._cleanups, [])
00022 
00023         cleanups = []
00024 
00025         def cleanup1(*args, **kwargs):
00026             cleanups.append((1, args, kwargs))
00027 
00028         def cleanup2(*args, **kwargs):
00029             cleanups.append((2, args, kwargs))
00030 
00031         test.addCleanup(cleanup1, 1, 2, 3, four='hello', five='goodbye')
00032         test.addCleanup(cleanup2)
00033 
00034         self.assertEqual(test._cleanups,
00035                          [(cleanup1, (1, 2, 3), dict(four='hello', five='goodbye')),
00036                           (cleanup2, (), {})])
00037 
00038         self.assertTrue(test.doCleanups())
00039         self.assertEqual(cleanups, [(2, (), {}), (1, (1, 2, 3), dict(four='hello', five='goodbye'))])

Definition at line 70 of file test_runner.py.

00070 
00071     def testCleanupInRun(self):
00072         blowUp = False
00073         ordering = []
00074 
00075         class TestableTest(unittest.TestCase):
00076             def setUp(self):
00077                 ordering.append('setUp')
00078                 if blowUp:
00079                     raise Exception('foo')
00080 
00081             def testNothing(self):
00082                 ordering.append('test')
00083 
00084             def tearDown(self):
00085                 ordering.append('tearDown')
00086 
00087         test = TestableTest('testNothing')
00088 
00089         def cleanup1():
00090             ordering.append('cleanup1')
00091         def cleanup2():
00092             ordering.append('cleanup2')
00093         test.addCleanup(cleanup1)
00094         test.addCleanup(cleanup2)
00095 
00096         def success(some_test):
00097             self.assertEqual(some_test, test)
00098             ordering.append('success')
00099 
00100         result = unittest.TestResult()
00101         result.addSuccess = success
00102 
00103         test.run(result)
00104         self.assertEqual(ordering, ['setUp', 'test', 'tearDown',
00105                                     'cleanup2', 'cleanup1', 'success'])
00106 
00107         blowUp = True
00108         ordering = []
00109         test = TestableTest('testNothing')
00110         test.addCleanup(cleanup1)
00111         test.run(result)
00112         self.assertEqual(ordering, ['setUp', 'cleanup1'])

Here is the call graph for this function:

Definition at line 40 of file test_runner.py.

00040 
00041     def testCleanUpWithErrors(self):
00042         class TestableTest(unittest.TestCase):
00043             def testNothing(self):
00044                 pass
00045 
00046         class MockOutcome(object):
00047             success = True
00048             errors = []
00049 
00050         test = TestableTest('testNothing')
00051         test._outcomeForDoCleanups = MockOutcome
00052 
00053         exc1 = Exception('foo')
00054         exc2 = Exception('bar')
00055         def cleanup1():
00056             raise exc1
00057 
00058         def cleanup2():
00059             raise exc2
00060 
00061         test.addCleanup(cleanup1)
00062         test.addCleanup(cleanup2)
00063 
00064         self.assertFalse(test.doCleanups())
00065         self.assertFalse(MockOutcome.success)
00066 
00067         (Type1, instance1, _), (Type2, instance2, _) = reversed(MockOutcome.errors)
00068         self.assertEqual((Type1, instance1), (Exception, exc1))
00069         self.assertEqual((Type2, instance2), (Exception, exc2))

Definition at line 113 of file test_runner.py.

00113 
00114     def testTestCaseDebugExecutesCleanups(self):
00115         ordering = []
00116 
00117         class TestableTest(unittest.TestCase):
00118             def setUp(self):
00119                 ordering.append('setUp')
00120                 self.addCleanup(cleanup1)
00121 
00122             def testNothing(self):
00123                 ordering.append('test')
00124 
00125             def tearDown(self):
00126                 ordering.append('tearDown')
00127 
00128         test = TestableTest('testNothing')
00129 
00130         def cleanup1():
00131             ordering.append('cleanup1')
00132             test.addCleanup(cleanup2)
00133         def cleanup2():
00134             ordering.append('cleanup2')
00135 
00136         test.debug()
00137         self.assertEqual(ordering, ['setUp', 'test', 'tearDown', 'cleanup1', 'cleanup2'])
00138 

Here is the call graph for this function:


The documentation for this class was generated from the following file: