From b019f08eb7f4c2e477f93b8c47d155f0de9f3772 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Mon, 25 May 2020 23:37:29 +0200 Subject: [PATCH 1/3] Deprecate unittest.makeSuite, unittest.findTestCases, and unittest.getTestCaseNames Scheduled for removal in Python 3.12 --- Doc/library/unittest.rst | 3 +++ Lib/test/support/__init__.py | 2 +- Lib/unittest/__init__.py | 1 + Lib/unittest/loader.py | 16 ++++++++++++++++ 4 files changed, 21 insertions(+), 1 deletion(-) 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/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) From f8e0b6ad3320d8ef19b9938e39b49cb0e854fafb Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Mon, 25 May 2020 23:58:35 +0200 Subject: [PATCH 2/3] Add NEWS --- .../next/Library/2020-05-25-23-58-29.bpo-5846.O9BIfm.rst | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2020-05-25-23-58-29.bpo-5846.O9BIfm.rst 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. From 5f3a60de056373c190625964ab6724554949b81b Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Tue, 17 Nov 2020 22:32:24 +0100 Subject: [PATCH 3/3] Add "What's new" --- Doc/whatsnew/3.10.rst | 4 ++++ 1 file changed, 4 insertions(+) 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 =======