diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst index e681a9d9746..544171af2ef 100644 --- a/Doc/whatsnew/3.13.rst +++ b/Doc/whatsnew/3.13.rst @@ -118,6 +118,20 @@ Removed * Remove support for using :class:`pathlib.Path` objects as context managers. This functionality was deprecated and made a no-op in Python 3.9. +* Removed the following :mod:`unittest` functions, deprecated in Python 3.11: + + * :func:`!unittest.findTestCases` + * :func:`!unittest.makeSuite` + * :func:`!unittest.getTestCaseNames` + + Use :class:`~unittest.TestLoader` methods instead: + + * :meth:`unittest.TestLoader.loadTestsFromModule` + * :meth:`unittest.TestLoader.loadTestsFromTestCase` + * :meth:`unittest.TestLoader.getTestCaseNames` + + (Contributed by Hugo van Kemenade in :gh:`104835`.) + * :pep:`594`: Remove the :mod:`!cgi`` and :mod:`!cgitb` modules, deprecated in Python 3.11. diff --git a/Lib/test/test_support.py b/Lib/test/test_support.py index 85d692f3097..cd1679dd232 100644 --- a/Lib/test/test_support.py +++ b/Lib/test/test_support.py @@ -430,10 +430,7 @@ class TestSupport(unittest.TestCase): extra = { 'TextTestResult', - 'findTestCases', - 'getTestCaseNames', 'installHandler', - 'makeSuite', } not_exported = {'load_tests', "TestProgram", "BaseTestSuite"} support.check__all__(self, diff --git a/Lib/test/test_unittest/test_loader.py b/Lib/test/test_unittest/test_loader.py index a203145a791..f32450c9223 100644 --- a/Lib/test/test_unittest/test_loader.py +++ b/Lib/test/test_unittest/test_loader.py @@ -1470,39 +1470,6 @@ class TestObsoleteFunctions(unittest.TestCase): def reverse_three_way_cmp(a, b): return unittest.util.three_way_cmp(b, a) - def test_getTestCaseNames(self): - with self.assertWarns(DeprecationWarning) as w: - tests = unittest.getTestCaseNames(self.MyTestCase, - prefix='check', sortUsing=self.reverse_three_way_cmp, - testNamePatterns=None) - self.assertEqual(w.filename, __file__) - self.assertEqual(tests, ['check_2', 'check_1']) - - def test_makeSuite(self): - with self.assertWarns(DeprecationWarning) as w: - suite = unittest.makeSuite(self.MyTestCase, - prefix='check', sortUsing=self.reverse_three_way_cmp, - suiteClass=self.MyTestSuite) - self.assertEqual(w.filename, __file__) - self.assertIsInstance(suite, self.MyTestSuite) - expected = self.MyTestSuite([self.MyTestCase('check_2'), - self.MyTestCase('check_1')]) - self.assertEqual(suite, expected) - - def test_findTestCases(self): - m = types.ModuleType('m') - m.testcase_1 = self.MyTestCase - - with self.assertWarns(DeprecationWarning) as w: - suite = unittest.findTestCases(m, - prefix='check', sortUsing=self.reverse_three_way_cmp, - suiteClass=self.MyTestSuite) - self.assertEqual(w.filename, __file__) - self.assertIsInstance(suite, self.MyTestSuite) - expected = [self.MyTestSuite([self.MyTestCase('check_2'), - self.MyTestCase('check_1')])] - self.assertEqual(list(suite), expected) - if __name__ == "__main__": unittest.main() diff --git a/Lib/unittest/__init__.py b/Lib/unittest/__init__.py index 5bcbf834840..f1f6c911ef1 100644 --- a/Lib/unittest/__init__.py +++ b/Lib/unittest/__init__.py @@ -51,10 +51,6 @@ __all__ = ['TestResult', 'TestCase', 'IsolatedAsyncioTestCase', 'TestSuite', 'registerResult', 'removeResult', 'removeHandler', 'addModuleCleanup', 'doModuleCleanups', 'enterModuleContext'] -# Expose obsolete functions for backwards compatibility -# bpo-5846: Deprecated in Python 3.11, scheduled for removal in Python 3.13. -__all__.extend(['getTestCaseNames', 'makeSuite', 'findTestCases']) - __unittest = True from .result import TestResult @@ -67,7 +63,6 @@ from .main import TestProgram, main from .runner import TextTestRunner, TextTestResult from .signals import installHandler, registerResult, removeResult, removeHandler # IsolatedAsyncioTestCase will be imported lazily. -from .loader import makeSuite, getTestCaseNames, findTestCases # Lazy import of IsolatedAsyncioTestCase from .async_case diff --git a/Lib/unittest/loader.py b/Lib/unittest/loader.py index b989284a640..678d627d7c6 100644 --- a/Lib/unittest/loader.py +++ b/Lib/unittest/loader.py @@ -437,47 +437,3 @@ class TestLoader(object): defaultTestLoader = TestLoader() - - -# These functions are considered obsolete for long time. -# They will be removed in Python 3.13. - -def _makeLoader(prefix, sortUsing, suiteClass=None, testNamePatterns=None): - loader = TestLoader() - loader.sortTestMethodsUsing = sortUsing - loader.testMethodPrefix = prefix - loader.testNamePatterns = testNamePatterns - if suiteClass: - loader.suiteClass = suiteClass - return loader - -def getTestCaseNames(testCaseClass, prefix, sortUsing=util.three_way_cmp, testNamePatterns=None): - import warnings - warnings.warn( - "unittest.getTestCaseNames() is deprecated and will be removed in Python 3.13. " - "Please use unittest.TestLoader.getTestCaseNames() instead.", - DeprecationWarning, stacklevel=2 - ) - return _makeLoader(prefix, sortUsing, testNamePatterns=testNamePatterns).getTestCaseNames(testCaseClass) - -def makeSuite(testCaseClass, prefix='test', sortUsing=util.three_way_cmp, - suiteClass=suite.TestSuite): - import warnings - warnings.warn( - "unittest.makeSuite() is deprecated and will be removed in Python 3.13. " - "Please use unittest.TestLoader.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): - import warnings - warnings.warn( - "unittest.findTestCases() is deprecated and will be removed in Python 3.13. " - "Please use unittest.TestLoader.loadTestsFromModule() instead.", - DeprecationWarning, stacklevel=2 - ) - return _makeLoader(prefix, sortUsing, suiteClass).loadTestsFromModule(\ - module) diff --git a/Misc/NEWS.d/3.11.0a1.rst b/Misc/NEWS.d/3.11.0a1.rst index 10e123e325c..284717a8764 100644 --- a/Misc/NEWS.d/3.11.0a1.rst +++ b/Misc/NEWS.d/3.11.0a1.rst @@ -3483,9 +3483,9 @@ Improved reprs of :mod:`threading` synchronization objects: Deprecated the following :mod:`unittest` functions, scheduled for removal in Python 3.13: -* :func:`~unittest.findTestCases` -* :func:`~unittest.makeSuite` -* :func:`~unittest.getTestCaseNames` +* :func:`~!unittest.findTestCases` +* :func:`~!unittest.makeSuite` +* :func:`~!unittest.getTestCaseNames` Use :class:`~unittest.TestLoader` methods instead: diff --git a/Misc/NEWS.d/next/Library/2023-05-24-08-45-04.gh-issue-104835.bN_B-B.rst b/Misc/NEWS.d/next/Library/2023-05-24-08-45-04.gh-issue-104835.bN_B-B.rst new file mode 100644 index 00000000000..f8e979b4739 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-05-24-08-45-04.gh-issue-104835.bN_B-B.rst @@ -0,0 +1,13 @@ +Removed the following :mod:`unittest` functions, deprecated in Python 3.11: + +* :func:`!unittest.findTestCases` +* :func:`!unittest.makeSuite` +* :func:`!unittest.getTestCaseNames` + +Use :class:`~unittest.TestLoader` methods instead: + +* :meth:`unittest.TestLoader.loadTestsFromModule` +* :meth:`unittest.TestLoader.loadTestsFromTestCase` +* :meth:`unittest.TestLoader.getTestCaseNames` + +Patch by Hugo van Kemenade.