diff options
author | Christian Heimes <christian@cheimes.de> | 2007-11-25 09:39:14 +0000 |
---|---|---|
committer | Christian Heimes <christian@cheimes.de> | 2007-11-25 09:39:14 +0000 |
commit | 4a22b5dee77b6a3439e4a09362586c390bbdef02 (patch) | |
tree | 670472c02e788fe4d027f7967fbbd8253e18cb5f /Lib/unittest.py | |
parent | 91c77301bf0246deabcdcd80bc7bedb169e2f964 (diff) | |
download | cpython-git-4a22b5dee77b6a3439e4a09362586c390bbdef02.tar.gz |
Patch from Georg Brandl and me for #1493
Remove unbound method objects
Diffstat (limited to 'Lib/unittest.py')
-rw-r--r-- | Lib/unittest.py | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/Lib/unittest.py b/Lib/unittest.py index c5905583e7..c4b124be10 100644 --- a/Lib/unittest.py +++ b/Lib/unittest.py @@ -559,13 +559,18 @@ class TestLoader: return self.loadTestsFromModule(obj) elif isinstance(obj, type) and issubclass(obj, TestCase): return self.loadTestsFromTestCase(obj) - elif (isinstance(obj, types.UnboundMethodType) and + elif (isinstance(obj, types.FunctionType) and isinstance(parent, type) and issubclass(parent, TestCase)): - return TestSuite([parent(obj.__name__)]) + name = obj.__name__ + inst = parent(name) + # static methods follow a different path + if not(isinstance(getattr(inst, name), types.FunctionType)): + return TestSuite([inst]) elif isinstance(obj, TestSuite): return obj - elif hasattr(obj, '__call__'): + + if hasattr(obj, '__call__'): test = obj() if isinstance(test, TestSuite): return test |