~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.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:
315
315
        self.report_success(test)
316
316
        self._cleanupLogFile(test)
317
317
        unittest.TestResult.addSuccess(self, test)
 
318
        test._log_contents = ''
318
319
 
319
320
    def _testConcluded(self, test):
320
321
        """Common code when a test has finished.
357
358
            # seems best to treat this as success from point-of-view of unittest
358
359
            # -- it actually does nothing so it barely matters :)
359
360
            unittest.TestResult.addSuccess(self, test)
 
361
            test._log_contents = ''
360
362
 
361
363
    def printErrorList(self, flavour, errors):
362
364
        for test, err in errors:
790
792
    _keep_log_file = False
791
793
    # record lsprof data when performing benchmark calls.
792
794
    _gather_lsprof_in_benchmarks = False
 
795
    attrs_to_keep = ('_testMethodName', '_testMethodDoc',
 
796
                     '_log_contents', '_log_file_name', '_benchtime',
 
797
                     '_TestCase__testMethodName')
793
798
 
794
799
    def __init__(self, methodName='testMethod'):
795
800
        super(TestCase, self).__init__(methodName)
1284
1289
                    result.addSuccess(self)
1285
1290
                result.stopTest(self)
1286
1291
                return
1287
 
        return unittest.TestCase.run(self, result)
 
1292
        try:
 
1293
            return unittest.TestCase.run(self, result)
 
1294
        finally:
 
1295
            saved_attrs = {}
 
1296
            absent_attr = object()
 
1297
            for attr_name in self.attrs_to_keep:
 
1298
                attr = getattr(self, attr_name, absent_attr)
 
1299
                if attr is not absent_attr:
 
1300
                    saved_attrs[attr_name] = attr
 
1301
            self.__dict__ = saved_attrs
1288
1302
 
1289
1303
    def tearDown(self):
1290
1304
        self._runCleanups()