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

Commit

Permalink
fixed monkey-patching logic, all tests now pass in python 2.7
Browse files Browse the repository at this point in the history
  • Loading branch information
timbertson committed Aug 19, 2011
1 parent 3fc4172 commit 8678dd8
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions mocktest/mocktest.py
Expand Up @@ -276,13 +276,19 @@ def run(self, result=None):
"""
if result is None: result = self.defaultTestResult()
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
if not getattr(addError, '_mocktest_patched', False):
def patchedAddError(*a, **k):
# be very cautious, as addError could change, and we've no good reason to break it.
if len(a) == 2 and len(a[1]) == 3:
type = a[1][0]
if issubclass(type, self.failureException):
# call it a failure instead of an error
return result.addFailure(*a, **k)
else:
import warnings
warnings.warn("unexpected argument set: (*%r, **%r)" % (a, k))
return addError(*a, **k)
patchedAddError._mocktest_patched = True
result.addError = patchedAddError
return super(TestCase, self).run(result)

0 comments on commit 8678dd8

Please sign in to comment.