summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSylvain Th?nault <sylvain.thenault@logilab.fr>2011-01-06 18:09:10 +0100
committerSylvain Th?nault <sylvain.thenault@logilab.fr>2011-01-06 18:09:10 +0100
commit9d26ddc592edb56db975fbc94c661befdccb35ee (patch)
tree587b439fe7f41824b7b6be24e24bd0ebe60e0f99
parentb643995a125f3d93c90a392887371f347221b9fb (diff)
downloadlogilab-common-9d26ddc592edb56db975fbc94c661befdccb35ee.tar.gz
testlib: proper assertRaises compatible with old usage and as unittest2 context manager
-rw-r--r--testlib.py12
1 files changed, 3 insertions, 9 deletions
diff --git a/testlib.py b/testlib.py
index 223d170..b4d381f 100644
--- a/testlib.py
+++ b/testlib.py
@@ -1143,25 +1143,19 @@ succeeded test into", osp.join(os.getcwd(), FILE_RESTART)
# XXX cube vcslib : test_branches_from_app
if callableObj is None:
_assert = super(TestCase, self).assertRaises
- return _assert(self, excClass, callableObj, *args, **kwargs)
+ return _assert(excClass, callableObj, *args, **kwargs)
try:
callableObj(*args, **kwargs)
except excClass, exc:
- class ProxyException(exc.__class__):
+ class ProxyException:
def __init__(self, obj):
- super(ProxyException, self).__setattr__("_obj", obj)
+ self._obj = obj
def __getattr__(self, attr):
warn_msg = ("This exception was retrieved with the old testlib way "
"`exc = self.assertRaises(Exc, callable)`, please use "
"the context manager instead'")
warnings.warn(warn_msg, DeprecationWarning, 2)
return self._obj.__getattribute__(attr)
- def __setattr__(self, attr, value):
- warn_msg = ("This exception was retrieved with the old testlib way "
- "`exc = self.assertRaises(Exc, callable)`, please use "
- "the context manager instead'")
- warnings.warn(warn_msg, DeprecationWarning, 2)
- return self._obj.__setattr__(attr, value)
return ProxyException(exc)
else:
if hasattr(excClass, '__name__'):