Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-5846: Deprecate obsolete methods makeSuite, findTestCases, and getTestCaseNames in unittest #20400

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Doc/library/unittest.rst
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
erlend-aasland marked this conversation as resolved.
Show resolved Hide 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
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`
erlend-aasland marked this conversation as resolved.
Show resolved Hide 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
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))
erlend-aasland marked this conversation as resolved.
Show resolved Hide resolved
_filter_suite(suite, match_test)
_run_suite(suite)

Expand Down
1 change: 1 addition & 0 deletions Lib/unittest/__init__.py
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
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
erlend-aasland marked this conversation as resolved.
Show resolved Hide 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.",
erlend-aasland marked this conversation as resolved.
Show resolved Hide 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.",
erlend-aasland marked this conversation as resolved.
Show resolved Hide 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)
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.