Skip to content

Commit b019f08

Browse files
author
Erlend E. Aasland
committed
Deprecate unittest.makeSuite, unittest.findTestCases, and unittest.getTestCaseNames
Scheduled for removal in Python 3.12
1 parent e59958f commit b019f08

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

Doc/library/unittest.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1830,6 +1830,9 @@ Loading and running tests
18301830
Return a sorted sequence of method names found within *testCaseClass*;
18311831
this should be a subclass of :class:`TestCase`.
18321832

1833+
.. deprecated:: 3.10
1834+
Scheduled for removal in Python 3.12.
1835+
18331836

18341837
.. method:: discover(start_dir, pattern='test*.py', top_level_dir=None)
18351838

Lib/test/support/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,7 @@ def run_unittest(*classes):
10771077
elif isinstance(cls, valid_types):
10781078
suite.addTest(cls)
10791079
else:
1080-
suite.addTest(unittest.makeSuite(cls))
1080+
suite.addTest(unittest.TestLoader().loadTestsFromTestCase(cls))
10811081
_filter_suite(suite, match_test)
10821082
_run_suite(suite)
10831083

Lib/unittest/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def testMultiply(self):
5252
'addModuleCleanup']
5353

5454
# Expose obsolete functions for backwards compatibility
55+
# Issue 5846: Deprecated in Python 3.10, scheduled for removal in Python 3.12.
5556
__all__.extend(['getTestCaseNames', 'makeSuite', 'findTestCases'])
5657

5758
__unittest = True

Lib/unittest/loader.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,15 +503,31 @@ def _makeLoader(prefix, sortUsing, suiteClass=None, testNamePatterns=None):
503503
loader.suiteClass = suiteClass
504504
return loader
505505

506+
# Issue 5846: getTestCaseNames, makeSuite, and findTestCases are deprecated as
507+
# of Python 3.10, scheduled for removal in Python 3.12.
506508
def getTestCaseNames(testCaseClass, prefix, sortUsing=util.three_way_cmp, testNamePatterns=None):
509+
warnings.warn(
510+
"getTestCaseNames() is deprecated and will be removed in Python 3.12.",
511+
DeprecationWarning, stacklevel=2
512+
)
507513
return _makeLoader(prefix, sortUsing, testNamePatterns=testNamePatterns).getTestCaseNames(testCaseClass)
508514

509515
def makeSuite(testCaseClass, prefix='test', sortUsing=util.three_way_cmp,
510516
suiteClass=suite.TestSuite):
517+
warnings.warn(
518+
"makeSuite() is deprecated and will be removed in Python 3.12. "
519+
"Please use loadTestsFromTestCase() instead.",
520+
DeprecationWarning, stacklevel=2
521+
)
511522
return _makeLoader(prefix, sortUsing, suiteClass).loadTestsFromTestCase(
512523
testCaseClass)
513524

514525
def findTestCases(module, prefix='test', sortUsing=util.three_way_cmp,
515526
suiteClass=suite.TestSuite):
527+
warnings.warn(
528+
"findTestCases() is deprecated and will be removed in Python 3.12. "
529+
"Please use loadTestsFromModule() instead.",
530+
DeprecationWarning, stacklevel=2
531+
)
516532
return _makeLoader(prefix, sortUsing, suiteClass).loadTestsFromModule(\
517533
module)

0 commit comments

Comments
 (0)