[Python-checkins] bpo-35767: Fix unittest.loader to allow partials as test_functions (#11600)
Łukasz Langa
webhook-mailer at python.org
Wed Jan 23 15:57:37 EST 2019
https://github.com/python/cpython/commit/fd628cf5adaeee73eab579393cdff71c8f70cdf2
commit: fd628cf5adaeee73eab579393cdff71c8f70cdf2
branch: master
author: Jason Fried <me at jasonfried.info>
committer: Łukasz Langa <lukasz at langa.pl>
date: 2019-01-23T21:57:25+01:00
summary:
bpo-35767: Fix unittest.loader to allow partials as test_functions (#11600)
files:
M Lib/unittest/loader.py
M Lib/unittest/test/test_loader.py
diff --git a/Lib/unittest/loader.py b/Lib/unittest/loader.py
index d936a96e73fb..ba7105e1ad60 100644
--- a/Lib/unittest/loader.py
+++ b/Lib/unittest/loader.py
@@ -229,7 +229,9 @@ def shouldIncludeMethod(attrname):
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)))
diff --git a/Lib/unittest/test/test_loader.py b/Lib/unittest/test/test_loader.py
index bfd722940b56..bc54bf055352 100644
--- a/Lib/unittest/test/test_loader.py
+++ b/Lib/unittest/test/test_loader.py
@@ -1,3 +1,4 @@
+import functools
import sys
import types
import warnings
@@ -1575,5 +1576,20 @@ def test_suiteClass__default_value(self):
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()
More information about the Python-checkins
mailing list