mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
#14971: Use class method name, not function.__name__, during unittest discovery.
This commit is contained in:
parent
f49581c2a1
commit
5e2f593145
3 changed files with 20 additions and 1 deletions
|
@ -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"
|
||||
#
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue