cpython: 659c89275be2 (original) (raw)
Mercurial > cpython
changeset 83247:659c89275be2
Merge #14971: Use class method name, not function.__name__, during unittest discovery. [#14971]
R David Murray rdmurray@bitdance.com | |
---|---|
date | Thu, 11 Apr 2013 08:58:11 -0400 |
parents | dd4aab6b683e(current diff)b17bcfadd7f3(diff) |
children | c1402fae0b02 |
files | Lib/unittest/loader.py Misc/NEWS |
diffstat | 3 files changed, 20 insertions(+), 1 deletions(-)[+] [-] Lib/unittest/loader.py 2 Lib/unittest/test/test_loader.py 16 Misc/NEWS 3 |
line wrap: on
line diff
--- a/Lib/unittest/loader.py +++ b/Lib/unittest/loader.py @@ -119,7 +119,7 @@ class TestLoader(object): elif (isinstance(obj, types.FunctionType) and isinstance(parent, type) and issubclass(parent, case.TestCase)):
name = obj.__name__[](#l1.7)
name = parts[-1][](#l1.8) inst = parent(name)[](#l1.9) # static methods follow a different path[](#l1.10) if not isinstance(getattr(inst, name), types.FunctionType):[](#l1.11)
--- a/Lib/unittest/test/test_loader.py +++ b/Lib/unittest/test/test_loader.py @@ -806,6 +806,22 @@ class Test_TestLoader(unittest.TestCase) ref_suite = unittest.TestSuite([MyTestCase('test')]) self.assertEqual(list(suite), [ref_suite])
#14971: Make sure the dotted name resolution works even if the actual
function doesn't have the same name as is used to find it.
- def test_loadTestsFromName__function_with_different_name_than_method(self):
# lambdas have the name '<lambda>'.[](#l2.10)
m = types.ModuleType('m')[](#l2.11)
class MyTestCase(unittest.TestCase):[](#l2.12)
test = lambda: 1[](#l2.13)
m.testcase_1 = MyTestCase[](#l2.14)
loader = unittest.TestLoader()[](#l2.16)
suite = loader.loadTestsFromNames(['testcase_1.test'], m)[](#l2.17)
self.assertIsInstance(suite, loader.suiteClass)[](#l2.18)
ref_suite = unittest.TestSuite([MyTestCase('test')])[](#l2.20)
self.assertEqual(list(suite), [ref_suite])[](#l2.21)
+ # "The specifier name is a ``dotted name'' that may resolve ... to ... a # test method within a test case class" #
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -34,6 +34,9 @@ Core and Builtins Library ------- +- Issue #14971: unittest test discovery no longer gets confused when a function