mirror of
https://github.com/python/cpython.git
synced 2025-08-30 05:35:08 +00:00
Merged in bugfix from PyUnit CVS for problem reported by Gary Todd.
If 'unittest.py' was run from the command line with the name of a test case class as a parameter, it failed with an ugly error. (Which was a shame, because the documentation says you can do that.) The problem was the old 'is the class X that you imported from me the same as my class X?' gotcha.
This commit is contained in:
parent
a38d2608bc
commit
e00dde2087
1 changed files with 4 additions and 3 deletions
|
@ -432,16 +432,17 @@ class TestLoader:
|
||||||
for part in parts:
|
for part in parts:
|
||||||
obj = getattr(obj, part)
|
obj = getattr(obj, part)
|
||||||
|
|
||||||
|
import unittest
|
||||||
if type(obj) == types.ModuleType:
|
if type(obj) == types.ModuleType:
|
||||||
return self.loadTestsFromModule(obj)
|
return self.loadTestsFromModule(obj)
|
||||||
elif type(obj) == types.ClassType and issubclass(obj, TestCase):
|
elif type(obj) == types.ClassType and issubclass(obj, unittest.TestCase):
|
||||||
return self.loadTestsFromTestCase(obj)
|
return self.loadTestsFromTestCase(obj)
|
||||||
elif type(obj) == types.UnboundMethodType:
|
elif type(obj) == types.UnboundMethodType:
|
||||||
return obj.im_class(obj.__name__)
|
return obj.im_class(obj.__name__)
|
||||||
elif callable(obj):
|
elif callable(obj):
|
||||||
test = obj()
|
test = obj()
|
||||||
if not isinstance(test, TestCase) and \
|
if not isinstance(test, unittest.TestCase) and \
|
||||||
not isinstance(test, TestSuite):
|
not isinstance(test, unittest.TestSuite):
|
||||||
raise ValueError, \
|
raise ValueError, \
|
||||||
"calling %s returned %s, not a test" % (obj,test)
|
"calling %s returned %s, not a test" % (obj,test)
|
||||||
return test
|
return test
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue