[pitivi: 5/10] tests/common.py: don't bother checking for leaks if test case ends in failure or error



commit d630a1abad27138b1a4f3f99a085cc0e183ce23f
Author: Brandon Lewis <brandon_lewis alum berkeley edu>
Date:   Wed Mar 3 17:46:06 2010 -0800

    tests/common.py: don't bother checking for leaks if test case ends in failure
    or error

 tests/common.py |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)
---
diff --git a/tests/common.py b/tests/common.py
index e4db30f..4294734 100644
--- a/tests/common.py
+++ b/tests/common.py
@@ -58,14 +58,28 @@ class TestCase(unittest.TestCase):
         del self._tracked
 
     def setUp(self):
+        self._num_failures = len(self._result.failures)
+        self._num_errors = len(self._result.errors)
         if detect_leaks:
             self.gctrack()
 
     def tearDown(self):
+        # don't barf gc info all over the console if we have already failed a
+        # test case
+        if ((self._num_failures < len(self._result.failures)) or
+            (self._num_errors < len(self._result.errors))):
+            return
         if detect_leaks:
             self.gccollect()
             self.gcverify()
 
+    # override run() to save a reference to the test result object
+    def run(self, result=None):
+        if not result:
+            result = self.defaultTestResult()
+        self._result = result
+        unittest.TestCase.run(self, result)
+
 # Some fake factories
 class FakeSourceFactory(SourceFactory):
     def __init__(self, factoryname="fakesrc", *args, **kwargs):



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]