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

bpo-5846: Deprecate obsolete methods makeSuite, findTestCases, and getTestCaseNames in unittest by erlend-aasland · Pull Request #20400 · python/cpython · GitHub

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

Filter by extension

Filter by extension .py  (3) .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
3 changes: 3 additions & 0 deletions Doc/library/unittest.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 @@ -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
Comment thread
erlend-aasland marked this conversation as resolved.
Scheduled for removal in Python 3.12.


.. method:: discover(start_dir, pattern='test*.py', top_level_dir=None)

Expand Down
4 changes: 4 additions & 0 deletions Doc/whatsnew/3.10.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 @@ -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`
Comment thread
erlend-aasland marked this conversation as resolved.
are now deprecated, scheduled for removal in Python 3.12.
(Contributed by Erlend E. Aasland in :issue:`5846`.)


Removed
=======
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/support/__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 @@ -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))
Comment thread
erlend-aasland marked this conversation as resolved.
_filter_suite(suite, match_test)
_run_suite(suite)

Expand Down
1 change: 1 addition & 0 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 @@ -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
Expand Down
16 changes: 16 additions & 0 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 @@ -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
Comment thread
erlend-aasland marked this conversation as resolved.
# 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.",
Comment thread
erlend-aasland marked this conversation as resolved.
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.",
Comment thread
erlend-aasland marked this conversation as resolved.
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)
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,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.

Back | FazBrowse Home | New Git URL