summaryrefslogtreecommitdiffstats
path: root/Lib/unittest/loader.py
diff options
context:
space:
mode:
authorGregory P. Smith <greg@krypto.org>2022-01-27 04:39:15 (GMT)
committerGitHub <noreply@github.com>2022-01-27 04:39:15 (GMT)
commitb50322d20337ca468f2070eedb051a16ee1eba94 (patch)
treeba478b8fe2b91b583cec640d518f9643fb5b6f7d /Lib/unittest/loader.py
parent9f0881476e0113d3a35e0ffa96649b9276dd75c5 (diff)
downloadcpython-b50322d20337ca468f2070eedb051a16ee1eba94.zip
cpython-b50322d20337ca468f2070eedb051a16ee1eba94.tar.gz
cpython-b50322d20337ca468f2070eedb051a16ee1eba94.tar.bz2
bpo-45162: Revert "Remove many old deprecated unittest features" (GH-30935)
Revert "bpo-45162: Remove many old deprecated unittest features (GH-28268)" This reverts commit b0a6ede3d0bd6fa4ffe413ab4dfc1059201df25b. We're deferring this change until 3.12 while upstream projects that use the legacy assertion method names are fixed. See the issue for links to the discussion. Many upstream projects now have issues and PRs filed.
Diffstat (limited to 'Lib/unittest/loader.py')
-rw-r--r--Lib/unittest/loader.py24
1 files changed, 23 insertions, 1 deletions
diff --git a/Lib/unittest/loader.py b/Lib/unittest/loader.py
index eb18cd0..7e6ce2f 100644
--- a/Lib/unittest/loader.py
+++ b/Lib/unittest/loader.py
@@ -93,8 +93,30 @@ class TestLoader(object):
loaded_suite = self.suiteClass(map(testCaseClass, testCaseNames))
return loaded_suite
- def loadTestsFromModule(self, module, *, pattern=None):
+ # XXX After Python 3.5, remove backward compatibility hacks for
+ # use_load_tests deprecation via *args and **kws. See issue 16662.
+ def loadTestsFromModule(self, module, *args, pattern=None, **kws):
"""Return a suite of all test cases contained in the given module"""
+ # This method used to take an undocumented and unofficial
+ # use_load_tests argument. For backward compatibility, we still
+ # accept the argument (which can also be the first position) but we
+ # ignore it and issue a deprecation warning if it's present.
+ if len(args) > 0 or 'use_load_tests' in kws:
+ warnings.warn('use_load_tests is deprecated and ignored',
+ DeprecationWarning)
+ kws.pop('use_load_tests', None)
+ if len(args) > 1:
+ # Complain about the number of arguments, but don't forget the
+ # required `module` argument.
+ complaint = len(args) + 1
+ raise TypeError('loadTestsFromModule() takes 1 positional argument but {} were given'.format(complaint))
+ if len(kws) != 0:
+ # Since the keyword arguments are unsorted (see PEP 468), just
+ # pick the alphabetically sorted first argument to complain about,
+ # if multiple were given. At least the error message will be
+ # predictable.
+ complaint = sorted(kws)[0]
+ raise TypeError("loadTestsFromModule() got an unexpected keyword argument '{}'".format(complaint))
tests = []
for name in dir(module):
obj = getattr(module, name)