diff options
author | R David Murray <rdmurray@bitdance.com> | 2013-04-11 12:58:11 (GMT) |
---|---|---|
committer | R David Murray <rdmurray@bitdance.com> | 2013-04-11 12:58:11 (GMT) |
commit | c601dc163932009b5d9f4e73eaa4204c2d47c468 (patch) | |
tree | b2b69f25a9cf3de86f727495e2d52bff9267fb95 /Lib/unittest/test | |
parent | f4216eacd9870191fd791a50a43b90c393349ad4 (diff) | |
parent | 5e2f59314588f4d263fe728ee8ba7da92f3439a0 (diff) | |
download | cpython-c601dc163932009b5d9f4e73eaa4204c2d47c468.zip cpython-c601dc163932009b5d9f4e73eaa4204c2d47c468.tar.gz cpython-c601dc163932009b5d9f4e73eaa4204c2d47c468.tar.bz2 |
Merge #14971: Use class method name, not function.__name__, during unittest discovery.
Diffstat (limited to 'Lib/unittest/test')
-rw-r--r-- | Lib/unittest/test/test_loader.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/Lib/unittest/test/test_loader.py b/Lib/unittest/test/test_loader.py index d1b9ef5..e86c09b 100644 --- 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>'. + m = types.ModuleType('m') + class MyTestCase(unittest.TestCase): + test = lambda: 1 + m.testcase_1 = MyTestCase + + loader = unittest.TestLoader() + suite = loader.loadTestsFromNames(['testcase_1.test'], m) + self.assertIsInstance(suite, loader.suiteClass) + + ref_suite = unittest.TestSuite([MyTestCase('test')]) + self.assertEqual(list(suite), [ref_suite]) + # "The specifier name is a ``dotted name'' that may resolve ... to ... a # test method within a test case class" # |