FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-104835: Remove unittest's deprecated getTestCaseNames, makeSuite, findTestCases by hugovk · Pull Request #104836 · python/cpython · GitHub

/ cpython Public
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (4) .rst  (3) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
14 changes: 14 additions & 0 deletions Doc/whatsnew/3.13.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
3 changes: 0 additions & 3 deletions Lib/test/test_support.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -430,10 +430,7 @@ def test_check__all__(self):

extra = {
'TextTestResult',
'findTestCases',
'getTestCaseNames',
'installHandler',
'makeSuite',
}
not_exported = {'load_tests', "TestProgram", "BaseTestSuite"}
support.check__all__(self,
Expand Down
33 changes: 0 additions & 33 deletions Lib/test/test_unittest/test_loader.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1470,39 +1470,6 @@ def test(self): pass
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()
5 changes: 0 additions & 5 deletions Lib/unittest/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ def testMultiply(self):
'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
Expand All @@ -67,7 +63,6 @@ def testMultiply(self):
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
Expand Down
44 changes: 0 additions & 44 deletions Lib/unittest/loader.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -437,47 +437,3 @@ def _find_test_path(self, full_path, pattern):


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)
6 changes: 3 additions & 3 deletions Misc/NEWS.d/3.11.0a1.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -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.

Back | FazBrowse Home | New Git URL