Skip to content
This repository has been archived by the owner on Mar 27, 2022. It is now read-only.

Commit

Permalink
removed run() method that only worked with python<2.7, and replace it…
Browse files Browse the repository at this point in the history
…s functionality by monkey-patching the result instance. Hopefully that is less fragile...
  • Loading branch information
timbertson committed Aug 17, 2011
1 parent e0dab9d commit ecf6fe0
Showing 1 changed file with 10 additions and 37 deletions.
47 changes: 10 additions & 37 deletions mocktest/mocktest.py
Expand Up @@ -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)

0 comments on commit ecf6fe0

Please sign in to comment.