Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fd628cf

Browse filesBrowse files
friedambv
authored andcommitted
bpo-35767: Fix unittest.loader to allow partials as test_functions (#11600)
1 parent f6243ac commit fd628cf
Copy full SHA for fd628cf

File tree

Expand file treeCollapse file tree

2 files changed

+19
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+19
-1
lines changed

‎Lib/unittest/loader.py

Copy file name to clipboardExpand all lines: Lib/unittest/loader.py
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,9 @@ def shouldIncludeMethod(attrname):
229229
testFunc = getattr(testCaseClass, attrname)
230230
if not callable(testFunc):
231231
return False
232-
fullName = '%s.%s' % (testCaseClass.__module__, testFunc.__qualname__)
232+
fullName = f'%s.%s.%s' % (
233+
testCaseClass.__module__, testCaseClass.__qualname__, attrname
234+
)
233235
return self.testNamePatterns is None or \
234236
any(fnmatchcase(fullName, pattern) for pattern in self.testNamePatterns)
235237
testFnNames = list(filter(shouldIncludeMethod, dir(testCaseClass)))

‎Lib/unittest/test/test_loader.py

Copy file name to clipboardExpand all lines: Lib/unittest/test/test_loader.py
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import functools
12
import sys
23
import types
34
import warnings
@@ -1575,5 +1576,20 @@ def test_suiteClass__default_value(self):
15751576
self.assertIs(loader.suiteClass, unittest.TestSuite)
15761577

15771578

1579+
def test_partial_functions(self):
1580+
def noop(arg):
1581+
pass
1582+
1583+
class Foo(unittest.TestCase):
1584+
pass
1585+
1586+
setattr(Foo, 'test_partial', functools.partial(noop, None))
1587+
1588+
loader = unittest.TestLoader()
1589+
1590+
test_names = ['test_partial']
1591+
self.assertEqual(loader.getTestCaseNames(Foo), test_names)
1592+
1593+
15781594
if __name__ == "__main__":
15791595
unittest.main()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.