diff options
author | Gustavo Niemeyer <gustavo@niemeyer.net> | 2007-12-04 22:50:33 -0200 |
---|---|---|
committer | Gustavo Niemeyer <gustavo@niemeyer.net> | 2007-12-04 22:50:33 -0200 |
commit | 47587fc40380290700dd6f182c255397cd17e75f (patch) | |
tree | 369fb89864453a07d417eefd91dd53b269524aee | |
parent | 06eb72f4966e8ca4e5c10e4880562923d83b5179 (diff) | |
download | mocker-47587fc40380290700dd6f182c255397cd17e75f.tar.gz |
In MockerTestCase's constructor, copy attributes from the original method
into the wrapper.
-rw-r--r-- | mocker.py | 7 | ||||
-rwxr-xr-x | test.py | 9 |
2 files changed, 15 insertions, 1 deletions
@@ -107,7 +107,12 @@ class MockerTestCase(unittest.TestCase): self.__cleanup() self.mocker.restore() self.mocker.verify() - test_method_wrapper.__doc__ = test_method.__doc__ + # Copy all attributes from the original method.. + for attr in dir(test_method): + # .. unless they're present in our wrapper already. + if not hasattr(test_method_wrapper, attr) or attr == "__doc__": + setattr(test_method_wrapper, attr, + getattr(test_method, attr)) setattr(self, methodName, test_method_wrapper) self.mocker = Mocker() @@ -276,6 +276,15 @@ class MockerTestCaseTest(TestCase): def test_has_expect(self): self.assertTrue(self.test.expect is expect) + def test_attributes_are_the_same(self): + class MyTest(MockerTestCase): + def test_method(self): + pass + test_method.foo = "bar" + test = MyTest("test_method") + self.assertEquals(getattr(test.test_method, "im_class", None), MyTest) + self.assertEquals(getattr(test.test_method, "foo", None), "bar") + def test_constructor_is_the_same(self): self.assertEquals(inspect.getargspec(TestCase.__init__), inspect.getargspec(MockerTestCase.__init__)) |