diff options
author | Erlend Egeberg Aasland <erlend.aasland@innova.no> | 2021-09-15 18:33:31 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-15 18:33:31 (GMT) |
commit | ff6d2cc55aac5cc53e331cae145d0cf35ec647b0 (patch) | |
tree | 4f2742e41fef18530c1f785ec538010fd9a71295 | |
parent | 9d76d28867c28bcc881b851547a9cd7ac003ae88 (diff) | |
download | cpython-ff6d2cc55aac5cc53e331cae145d0cf35ec647b0.zip cpython-ff6d2cc55aac5cc53e331cae145d0cf35ec647b0.tar.gz cpython-ff6d2cc55aac5cc53e331cae145d0cf35ec647b0.tar.bz2 |
bpo-5846: Deprecate obsolete methods in `unittest` (GH-28299)
Deprecate makeSuite, findTestCases, and getTestCaseNames. Scheduled for removal in Python 3.13.
-rw-r--r-- | Doc/whatsnew/3.11.rst | 15 | ||||
-rw-r--r-- | Lib/test/test_support.py | 9 | ||||
-rw-r--r-- | Lib/unittest/__init__.py | 35 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Library/2020-05-25-23-58-29.bpo-5846.O9BIfm.rst | 14 |
4 files changed, 69 insertions, 4 deletions
diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index a06a075..df331ed 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -352,6 +352,21 @@ Deprecated :class:`~unittest.IsolatedAsyncioTestCase` test methods (other than the default ``None`` value), is now deprecated. +* Deprecated the following :mod:`unittest` functions, scheduled for removal in + Python 3.13: + + * :func:`unittest.findTestCases` + * :func:`unittest.makeSuite` + * :func:`unittest.getTestCaseNames` + + Use :class:`~unittest.TestLoader` method instead: + + * :meth:`unittest.TestLoader.loadTestsFromModule` + * :meth:`unittest.TestLoader.loadTestsFromTestCase` + * :meth:`unittest.TestLoader.getTestCaseNames` + + (Contributed by Erlend E. Aasland in :issue:`5846`.) + Removed ======= diff --git a/Lib/test/test_support.py b/Lib/test/test_support.py index 11ca0c2..44fe334 100644 --- a/Lib/test/test_support.py +++ b/Lib/test/test_support.py @@ -426,9 +426,14 @@ class TestSupport(unittest.TestCase): extra=extra, not_exported=not_exported) - extra = {'TextTestResult', 'installHandler'} + extra = { + 'TextTestResult', + 'findTestCases', + 'getTestCaseNames', + 'installHandler', + 'makeSuite', + } not_exported = {'load_tests', "TestProgram", "BaseTestSuite"} - support.check__all__(self, unittest, ("unittest.result", "unittest.case", diff --git a/Lib/unittest/__init__.py b/Lib/unittest/__init__.py index 348dc47..e318c63 100644 --- a/Lib/unittest/__init__.py +++ b/Lib/unittest/__init__.py @@ -52,6 +52,7 @@ __all__ = ['TestResult', 'TestCase', 'IsolatedAsyncioTestCase', 'TestSuite', 'addModuleCleanup'] # 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 @@ -60,8 +61,7 @@ from .result import TestResult from .case import (addModuleCleanup, TestCase, FunctionTestCase, SkipTest, skip, skipIf, skipUnless, expectedFailure) from .suite import BaseTestSuite, TestSuite -from .loader import (TestLoader, defaultTestLoader, makeSuite, getTestCaseNames, - findTestCases) +from .loader import TestLoader, defaultTestLoader from .main import TestProgram, main from .runner import TextTestRunner, TextTestResult from .signals import installHandler, registerResult, removeResult, removeHandler @@ -70,6 +70,37 @@ from .signals import installHandler, registerResult, removeResult, removeHandler # deprecated _TextTestResult = TextTestResult +from .loader import ( + makeSuite as _makeSuite, + findTestCases as _findTestCases, + getTestCaseNames as _getTestCaseNames, +) + +import warnings +def makeSuite(*args, **kwargs): + warnings.warn( + "unittest.makeSuite() is deprecated and will be removed in Python 3.13. " + "Please use unittest.TestLoader.loadTestsFromTestCase() instead.", + DeprecationWarning, stacklevel=2 + ) + return _makeSuite(*args, **kwargs) + +def getTestCaseNames(*args, **kwargs): + warnings.warn( + "unittest.getTestCaseNames() is deprecated and will be removed in Python 3.13. " + "Please use unittest.TestLoader.getTestCaseNames() instead.", + DeprecationWarning, stacklevel=2 + ) + return _getTestCaseNames(*args, **kwargs) + +def findTestCases(*args, **kwargs): + warnings.warn( + "unittest.findTestCases() is deprecated and will be removed in Python 3.13. " + "Please use unittest.TestLoader.loadTestsFromModule() instead.", + DeprecationWarning, stacklevel=2 + ) + return _findTestCases(*args, **kwargs) + # There are no tests here, so don't try to run anything discovered from # introspecting the symbols (e.g. FunctionTestCase). Instead, all our # tests come from within unittest.test. 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 0000000..556c54d --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-05-25-23-58-29.bpo-5846.O9BIfm.rst @@ -0,0 +1,14 @@ +Deprecated the following :mod:`unittest` functions, scheduled for removal in +Python 3.13: + +* :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 Erlend E. Aasland. |