]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-35767: Fix unittest.loader to allow partials as test_functions (GH-11600) (#11662) 11672/head
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Thu, 24 Jan 2019 17:30:59 +0000 (09:30 -0800)
committerŁukasz Langa <lukasz@langa.pl>
Thu, 24 Jan 2019 17:30:59 +0000 (18:30 +0100)
(cherry picked from commit fd628cf5adaeee73eab579393cdff71c8f70cdf2)

Co-authored-by: Jason Fried <me@jasonfried.info>
Lib/unittest/loader.py
Lib/unittest/test/test_loader.py

index d936a96e73fbc77a8e0e9108ce898010aae3aa6d..ba7105e1ad6039ffbd3f9ea61566d1e6e204954d 100644 (file)
@@ -229,7 +229,9 @@ class TestLoader(object):
             testFunc = getattr(testCaseClass, attrname)
             if not callable(testFunc):
                 return False
-            fullName = '%s.%s' % (testCaseClass.__module__, testFunc.__qualname__)
+            fullName = f'%s.%s.%s' % (
+                testCaseClass.__module__, testCaseClass.__qualname__, attrname
+            )
             return self.testNamePatterns is None or \
                 any(fnmatchcase(fullName, pattern) for pattern in self.testNamePatterns)
         testFnNames = list(filter(shouldIncludeMethod, dir(testCaseClass)))
index bfd722940b5683f2990bcba38ad5740ae93429b2..bc54bf0553528d0ab239515cabb06b42a19a269c 100644 (file)
@@ -1,3 +1,4 @@
+import functools
 import sys
 import types
 import warnings
@@ -1575,5 +1576,20 @@ class Test_TestLoader(unittest.TestCase):
         self.assertIs(loader.suiteClass, unittest.TestSuite)
 
 
+    def test_partial_functions(self):
+        def noop(arg):
+            pass
+
+        class Foo(unittest.TestCase):
+            pass
+
+        setattr(Foo, 'test_partial', functools.partial(noop, None))
+
+        loader = unittest.TestLoader()
+
+        test_names = ['test_partial']
+        self.assertEqual(loader.getTestCaseNames(Foo), test_names)
+
+
 if __name__ == "__main__":
     unittest.main()