~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_selftest.py

Reduce memory consumption of the test suite by resetting the __dict__
        of successful TestCases. (Andrew Bennetts)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1120
1120
        self.assertTrue(result.wasSuccessful())
1121
1121
 
1122
1122
    def test_skipped_from_setup(self):
 
1123
        calls = []
1123
1124
        class SkippedSetupTest(TestCase):
1124
1125
 
1125
1126
            def setUp(self):
1126
 
                self.counter = 1
 
1127
                calls.append('setUp')
1127
1128
                self.addCleanup(self.cleanup)
1128
1129
                raise TestSkipped('skipped setup')
1129
1130
 
1131
1132
                self.fail('test reached')
1132
1133
 
1133
1134
            def cleanup(self):
1134
 
                self.counter -= 1
 
1135
                calls.append('cleanup')
1135
1136
 
1136
1137
        runner = TextTestRunner(stream=self._log_file)
1137
1138
        test = SkippedSetupTest('test_skip')
1138
1139
        result = self.run_test_runner(runner, test)
1139
1140
        self.assertTrue(result.wasSuccessful())
1140
1141
        # Check if cleanup was called the right number of times.
1141
 
        self.assertEqual(0, test.counter)
 
1142
        self.assertEqual(['setUp', 'cleanup'], calls)
1142
1143
 
1143
1144
    def test_skipped_from_test(self):
 
1145
        calls = []
1144
1146
        class SkippedTest(TestCase):
1145
1147
 
1146
1148
            def setUp(self):
1147
 
                self.counter = 1
 
1149
                calls.append('setUp')
1148
1150
                self.addCleanup(self.cleanup)
1149
1151
 
1150
1152
            def test_skip(self):
1151
1153
                raise TestSkipped('skipped test')
1152
1154
 
1153
1155
            def cleanup(self):
1154
 
                self.counter -= 1
 
1156
                calls.append('cleanup')
1155
1157
 
1156
1158
        runner = TextTestRunner(stream=self._log_file)
1157
1159
        test = SkippedTest('test_skip')
1158
1160
        result = self.run_test_runner(runner, test)
1159
1161
        self.assertTrue(result.wasSuccessful())
1160
1162
        # Check if cleanup was called the right number of times.
1161
 
        self.assertEqual(0, test.counter)
 
1163
        self.assertEqual(['setUp', 'cleanup'], calls)
1162
1164
 
1163
1165
    def test_not_applicable(self):
1164
1166
        # run a test that is skipped because it's not applicable