diff --git a/Doc/library/unittest.rst b/Doc/library/unittest.rst index 51e10119d3e8d0..edb1488df586eb 100644 --- a/Doc/library/unittest.rst +++ b/Doc/library/unittest.rst @@ -1830,6 +1830,9 @@ Loading and running tests Return a sorted sequence of method names found within *testCaseClass*; this should be a subclass of :class:`TestCase`. + .. deprecated:: 3.10 + Scheduled for removal in Python 3.12. + .. method:: discover(start_dir, pattern='test*.py', top_level_dir=None) diff --git a/Doc/whatsnew/3.10.rst b/Doc/whatsnew/3.10.rst index 786cc61003a593..e3bcef8463f6e5 100644 --- a/Doc/whatsnew/3.10.rst +++ b/Doc/whatsnew/3.10.rst @@ -365,6 +365,10 @@ Deprecated scheduled for removal in Python 3.12. (Contributed by Erlend E. Aasland in :issue:`42264`.) +* :meth:`unittest.makeSuite`, :meth:`unittest.findTestCases`, and :meth:`unittest.getTestCaseNames` + are now deprecated, scheduled for removal in Python 3.12. + (Contributed by Erlend E. Aasland in :issue:`5846`.) + Removed ======= diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index 4ba749454c1873..7927d651f70f02 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -1077,7 +1077,7 @@ def run_unittest(*classes): elif isinstance(cls, valid_types): suite.addTest(cls) else: - suite.addTest(unittest.makeSuite(cls)) + suite.addTest(unittest.TestLoader().loadTestsFromTestCase(cls)) _filter_suite(suite, match_test) _run_suite(suite) diff --git a/Lib/unittest/__init__.py b/Lib/unittest/__init__.py index 348dc471f4c3d4..5907ab197eae2e 100644 --- a/Lib/unittest/__init__.py +++ b/Lib/unittest/__init__.py @@ -52,6 +52,7 @@ def testMultiply(self): 'addModuleCleanup'] # Expose obsolete functions for backwards compatibility +# Issue 5846: Deprecated in Python 3.10, scheduled for removal in Python 3.12. __all__.extend(['getTestCaseNames', 'makeSuite', 'findTestCases']) __unittest = True diff --git a/Lib/unittest/loader.py b/Lib/unittest/loader.py index ba7105e1ad6039..f3871ad76fb72c 100644 --- a/Lib/unittest/loader.py +++ b/Lib/unittest/loader.py @@ -503,15 +503,31 @@ def _makeLoader(prefix, sortUsing, suiteClass=None, testNamePatterns=None): loader.suiteClass = suiteClass return loader +# Issue 5846: getTestCaseNames, makeSuite, and findTestCases are deprecated as +# of Python 3.10, scheduled for removal in Python 3.12. def getTestCaseNames(testCaseClass, prefix, sortUsing=util.three_way_cmp, testNamePatterns=None): + warnings.warn( + "getTestCaseNames() is deprecated and will be removed in Python 3.12.", + DeprecationWarning, stacklevel=2 + ) return _makeLoader(prefix, sortUsing, testNamePatterns=testNamePatterns).getTestCaseNames(testCaseClass) def makeSuite(testCaseClass, prefix='test', sortUsing=util.three_way_cmp, suiteClass=suite.TestSuite): + warnings.warn( + "makeSuite() is deprecated and will be removed in Python 3.12. " + "Please use loadTestsFromTestCase() instead.", + DeprecationWarning, stacklevel=2 + ) return _makeLoader(prefix, sortUsing, suiteClass).loadTestsFromTestCase( testCaseClass) def findTestCases(module, prefix='test', sortUsing=util.three_way_cmp, suiteClass=suite.TestSuite): + warnings.warn( + "findTestCases() is deprecated and will be removed in Python 3.12. " + "Please use loadTestsFromModule() instead.", + DeprecationWarning, stacklevel=2 + ) return _makeLoader(prefix, sortUsing, suiteClass).loadTestsFromModule(\ module) diff --git a/Misc/NEWS.d/next/Library/2020-05-25-23-58-29.bpo-5846.O9BIfm.rst b/Misc/NEWS.d/next/Library/2020-05-25-23-58-29.bpo-5846.O9BIfm.rst new file mode 100644 index 00000000000000..e5fd7b2569378d --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-05-25-23-58-29.bpo-5846.O9BIfm.rst @@ -0,0 +1,4 @@ +:meth:`unittest.findTestCases`, :meth:`unittest.makeSuite`, and +:meth:`unittest.getTestCaseNames` are now deprecated, scheduled for removal in +Python 3.12. +Patch by Erlend E. Aasland.