mirror of
https://github.com/python/cpython.git
synced 2025-08-30 13:38:43 +00:00
gh-104835: Remove unittest's deprecated getTestCaseNames, makeSuite, findTestCases (#104836)
This commit is contained in:
parent
ded5f1f287
commit
b1cb30ec86
7 changed files with 30 additions and 88 deletions
|
@ -118,6 +118,20 @@ Removed
|
||||||
* Remove support for using :class:`pathlib.Path` objects as context managers.
|
* Remove support for using :class:`pathlib.Path` objects as context managers.
|
||||||
This functionality was deprecated and made a no-op in Python 3.9.
|
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,
|
* :pep:`594`: Remove the :mod:`!cgi`` and :mod:`!cgitb` modules,
|
||||||
deprecated in Python 3.11.
|
deprecated in Python 3.11.
|
||||||
|
|
||||||
|
|
|
@ -430,10 +430,7 @@ class TestSupport(unittest.TestCase):
|
||||||
|
|
||||||
extra = {
|
extra = {
|
||||||
'TextTestResult',
|
'TextTestResult',
|
||||||
'findTestCases',
|
|
||||||
'getTestCaseNames',
|
|
||||||
'installHandler',
|
'installHandler',
|
||||||
'makeSuite',
|
|
||||||
}
|
}
|
||||||
not_exported = {'load_tests', "TestProgram", "BaseTestSuite"}
|
not_exported = {'load_tests', "TestProgram", "BaseTestSuite"}
|
||||||
support.check__all__(self,
|
support.check__all__(self,
|
||||||
|
|
|
@ -1470,39 +1470,6 @@ class TestObsoleteFunctions(unittest.TestCase):
|
||||||
def reverse_three_way_cmp(a, b):
|
def reverse_three_way_cmp(a, b):
|
||||||
return unittest.util.three_way_cmp(b, a)
|
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__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -51,10 +51,6 @@ __all__ = ['TestResult', 'TestCase', 'IsolatedAsyncioTestCase', 'TestSuite',
|
||||||
'registerResult', 'removeResult', 'removeHandler',
|
'registerResult', 'removeResult', 'removeHandler',
|
||||||
'addModuleCleanup', 'doModuleCleanups', 'enterModuleContext']
|
'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
|
__unittest = True
|
||||||
|
|
||||||
from .result import TestResult
|
from .result import TestResult
|
||||||
|
@ -67,7 +63,6 @@ from .main import TestProgram, main
|
||||||
from .runner import TextTestRunner, TextTestResult
|
from .runner import TextTestRunner, TextTestResult
|
||||||
from .signals import installHandler, registerResult, removeResult, removeHandler
|
from .signals import installHandler, registerResult, removeResult, removeHandler
|
||||||
# IsolatedAsyncioTestCase will be imported lazily.
|
# IsolatedAsyncioTestCase will be imported lazily.
|
||||||
from .loader import makeSuite, getTestCaseNames, findTestCases
|
|
||||||
|
|
||||||
|
|
||||||
# Lazy import of IsolatedAsyncioTestCase from .async_case
|
# Lazy import of IsolatedAsyncioTestCase from .async_case
|
||||||
|
|
|
@ -437,47 +437,3 @@ class TestLoader(object):
|
||||||
|
|
||||||
|
|
||||||
defaultTestLoader = TestLoader()
|
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)
|
|
||||||
|
|
|
@ -3483,9 +3483,9 @@ Improved reprs of :mod:`threading` synchronization objects:
|
||||||
Deprecated the following :mod:`unittest` functions, scheduled for removal in
|
Deprecated the following :mod:`unittest` functions, scheduled for removal in
|
||||||
Python 3.13:
|
Python 3.13:
|
||||||
|
|
||||||
* :func:`~unittest.findTestCases`
|
* :func:`~!unittest.findTestCases`
|
||||||
* :func:`~unittest.makeSuite`
|
* :func:`~!unittest.makeSuite`
|
||||||
* :func:`~unittest.getTestCaseNames`
|
* :func:`~!unittest.getTestCaseNames`
|
||||||
|
|
||||||
Use :class:`~unittest.TestLoader` methods instead:
|
Use :class:`~unittest.TestLoader` methods instead:
|
||||||
|
|
||||||
|
|
|
@ -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.
|
Loading…
Add table
Add a link
Reference in a new issue