Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

removed run() method that only worked with python<2.7, and replace it…

…s functionality by monkey-patching the result instance. Hopefully that is less fragile...
  • Loading branch information...
commit ecf6fe00567f0a00e7f082f035aed8e2d666c2ed 1 parent e0dab9d
@gfxmonk authored
Showing with 10 additions and 37 deletions.
  1. +10 −37 mocktest/mocktest.py
View
47 mocktest/mocktest.py
@@ -275,41 +275,14 @@ def run(self, result=None):
in the teardown method counts for a failure
"""
if result is None: result = self.defaultTestResult()
- result.startTest(self)
- testMethod = getattr(self, self._testMethodName)
- try:
- try:
- self.setUp()
- except KeyboardInterrupt:
- raise
- except:
- result.addError(self, self._exc_info())
- return
-
- ok = False
- try:
- testMethod()
- ok = True
- except self.failureException:
- result.addFailure(self, self._exc_info())
- except KeyboardInterrupt:
- raise
- except:
- result.addError(self, self._exc_info())
-
- try:
- self.tearDown()
- except self.failureException:
- # ignore this failure if the test already failed
- if ok:
- result.addFailure(self, self._exc_info())
- ok = False
- except KeyboardInterrupt:
- raise
- except:
- result.addError(self, self._exc_info())
- ok = False
- if ok: result.addSuccess(self)
- finally:
- result.stopTest(self)
+ addError = result.addError
+ def patchedAddError(*a, **k):
+ if len(a) == 1 and len(a[0]) == 3:
+ type = a[0][0]
+ if issubclass(type, self.failureException):
+ # call it a failure instead of an error
+ return result.addFailure(*a, **k)
+ return addError(*a, **k)
+ result.addError = patchedAddError
+ return super(TestCase, self).run(result)
Please sign in to comment.
Something went wrong with that request. Please try again.