[Python-checkins] Revert "bpo-45162: Revert "Remove many old deprecated unittest features"" (GH-92556)

serhiy-storchaka webhook-mailer at python.org
Sun Jun 26 03:18:17 EDT 2022


https://github.com/python/cpython/commit/c834c025695f598a0df3aba980257326a088044a
commit: c834c025695f598a0df3aba980257326a088044a
branch: main
author: Serhiy Storchaka <storchaka at gmail.com>
committer: serhiy-storchaka <storchaka at gmail.com>
date: 2022年06月26日T10:18:06+03:00
summary:
Revert "bpo-45162: Revert "Remove many old deprecated unittest features"" (GH-92556)
This reverts commit b50322d20337ca468f2070eedb051a16ee1eba94.
files:
A Misc/NEWS.d/next/Library/2022-05-14-09-01-38.gh-issue-89325.ys-2BZ.rst
M Doc/library/unittest.rst
M Doc/whatsnew/3.12.rst
M Doc/whatsnew/3.2.rst
M Lib/test/test_unittest/_test_warnings.py
M Lib/test/test_unittest/test_assertions.py
M Lib/test/test_unittest/test_case.py
M Lib/test/test_unittest/test_loader.py
M Lib/test/test_unittest/test_program.py
M Lib/test/test_unittest/test_runner.py
M Lib/unittest/__init__.py
M Lib/unittest/case.py
M Lib/unittest/loader.py
M Lib/unittest/runner.py
diff --git a/Doc/library/unittest.rst b/Doc/library/unittest.rst
index e07a32b88b1c3..331f67cba23b5 100644
--- a/Doc/library/unittest.rst
+++ b/Doc/library/unittest.rst
@@ -1261,9 +1261,6 @@ Test cases
 :meth:`.assertRegex`.
 .. versionadded:: 3.2
 :meth:`.assertNotRegex`.
- .. versionadded:: 3.5
- The name ``assertNotRegexpMatches`` is a deprecated alias
- for :meth:`.assertNotRegex`.
 
 
 .. method:: assertCountEqual(first, second, msg=None)
@@ -1660,40 +1657,6 @@ Test cases
 :mod:`unittest`-based test framework.
 
 
-.. _deprecated-aliases:
-
-Deprecated aliases
-##################
-
-For historical reasons, some of the :class:`TestCase` methods had one or more
-aliases that are now deprecated. The following table lists the correct names
-along with their deprecated aliases:
-
- ============================== ====================== =======================
- Method Name Deprecated alias Deprecated alias
- ============================== ====================== =======================
- :meth:`.assertEqual` failUnlessEqual assertEquals
- :meth:`.assertNotEqual` failIfEqual assertNotEquals
- :meth:`.assertTrue` failUnless assert\_
- :meth:`.assertFalse` failIf
- :meth:`.assertRaises` failUnlessRaises
- :meth:`.assertAlmostEqual` failUnlessAlmostEqual assertAlmostEquals
- :meth:`.assertNotAlmostEqual` failIfAlmostEqual assertNotAlmostEquals
- :meth:`.assertRegex` assertRegexpMatches
- :meth:`.assertNotRegex` assertNotRegexpMatches
- :meth:`.assertRaisesRegex` assertRaisesRegexp
- ============================== ====================== =======================
-
- .. deprecated:: 3.1
- The fail* aliases listed in the second column have been deprecated.
- .. deprecated:: 3.2
- The assert* aliases listed in the third column have been deprecated.
- .. deprecated:: 3.2
- ``assertRegexpMatches`` and ``assertRaisesRegexp`` have been renamed to
- :meth:`.assertRegex` and :meth:`.assertRaisesRegex`.
- .. deprecated:: 3.5
- The ``assertNotRegexpMatches`` name is deprecated in favor of :meth:`.assertNotRegex`.
-
 .. _testsuite-objects:
 
 Grouping tests
@@ -1819,7 +1782,7 @@ Loading and running tests
 case is created for that method instead.
 
 
- .. method:: loadTestsFromModule(module, pattern=None)
+ .. method:: loadTestsFromModule(module, *, pattern=None)
 
 Return a suite of all test cases contained in the given module. This
 method searches *module* for classes derived from :class:`TestCase` and
@@ -1843,10 +1806,11 @@ Loading and running tests
 Support for ``load_tests`` added.
 
 .. versionchanged:: 3.5
- The undocumented and unofficial *use_load_tests* default argument is
- deprecated and ignored, although it is still accepted for backward
- compatibility. The method also now accepts a keyword-only argument
- *pattern* which is passed to ``load_tests`` as the third argument.
+ Support for a keyword-only argument *pattern* has been added.
+
+ .. versionchanged:: 3.12
+ The undocumented and unofficial *use_load_tests* parameter has been
+ removed.
 
 
 .. method:: loadTestsFromName(name, module=None)
@@ -2203,8 +2167,6 @@ Loading and running tests
 :class:`TextTestRunner`.
 
 .. versionadded:: 3.2
- This class was previously named ``_TextTestResult``. The old name still
- exists as an alias but is deprecated.
 
 
 .. data:: defaultTestLoader
@@ -2227,10 +2189,7 @@ Loading and running tests
 By default this runner shows :exc:`DeprecationWarning`,
 :exc:`PendingDeprecationWarning`, :exc:`ResourceWarning` and
 :exc:`ImportWarning` even if they are :ref:`ignored by default
- <warning-ignored>`. Deprecation warnings caused by :ref:`deprecated unittest
- methods <deprecated-aliases>` are also special-cased and, when the warning
- filters are ``'default'`` or ``'always'``, they will appear only once
- per-module, in order to avoid too many warning messages. This behavior can
+ <warning-ignored>`. This behavior can
 be overridden using Python's :option:`!-Wd` or :option:`!-Wa` options
 (see :ref:`Warning control <using-on-warnings>`) and leaving
 *warnings* to ``None``.
diff --git a/Doc/whatsnew/3.12.rst b/Doc/whatsnew/3.12.rst
index f8de5f503e731..849a74a854220 100644
--- a/Doc/whatsnew/3.12.rst
+++ b/Doc/whatsnew/3.12.rst
@@ -178,6 +178,45 @@ although there is currently no date scheduled for their removal.
 Removed
 =======
 
+* Removed many old deprecated :mod:`unittest` features:
+
+ - A number of :class:`~unittest.TestCase` method aliases:
+
+ ============================ =============================== ===============
+ Deprecated alias Method Name Deprecated in
+ ============================ =============================== ===============
+ ``failUnless`` :meth:`.assertTrue` 3.1
+ ``failIf`` :meth:`.assertFalse` 3.1
+ ``failUnlessEqual`` :meth:`.assertEqual` 3.1
+ ``failIfEqual`` :meth:`.assertNotEqual` 3.1
+ ``failUnlessAlmostEqual`` :meth:`.assertAlmostEqual` 3.1
+ ``failIfAlmostEqual`` :meth:`.assertNotAlmostEqual` 3.1
+ ``failUnlessRaises`` :meth:`.assertRaises` 3.1
+ ``assert_`` :meth:`.assertTrue` 3.2
+ ``assertEquals`` :meth:`.assertEqual` 3.2
+ ``assertNotEquals`` :meth:`.assertNotEqual` 3.2
+ ``assertAlmostEquals`` :meth:`.assertAlmostEqual` 3.2
+ ``assertNotAlmostEquals`` :meth:`.assertNotAlmostEqual` 3.2
+ ``assertRegexpMatches`` :meth:`.assertRegex` 3.2
+ ``assertRaisesRegexp`` :meth:`.assertRaisesRegex` 3.2
+ ``assertNotRegexpMatches`` :meth:`.assertNotRegex` 3.5
+ ============================ =============================== ===============
+
+ You can use https://github.com/isidentical/teyit to automatically modernise
+ your unit tests.
+
+ - Undocumented and broken :class:`~unittest.TestCase` method
+ ``assertDictContainsSubset`` (deprecated in Python 3.2).
+
+ - Undocumented :meth:`TestLoader.loadTestsFromModule
+ <unittest.TestLoader.loadTestsFromModule>` parameter *use_load_tests*
+ (deprecated and ignored since Python 3.2).
+
+ - An alias of the :class:`~unittest.TextTestResult` class:
+ ``_TextTestResult`` (deprecated in Python 3.2).
+
+ (Contributed by Serhiy Storchaka in :issue:`45162`.)
+
 * Several names deprecated in the :mod:`configparser` way back in 3.2 have
 been removed per :gh:`89336`:
 
diff --git a/Doc/whatsnew/3.2.rst b/Doc/whatsnew/3.2.rst
index 125eed6b0cbcb..9dd849f9e9e72 100644
--- a/Doc/whatsnew/3.2.rst
+++ b/Doc/whatsnew/3.2.rst
@@ -1817,8 +1817,7 @@ names.
 =============================== ==============================
 
 Likewise, the ``TestCase.fail*`` methods deprecated in Python 3.1 are expected
- to be removed in Python 3.3. Also see the :ref:`deprecated-aliases` section in
- the :mod:`unittest` documentation.
+ to be removed in Python 3.3.
 
 (Contributed by Ezio Melotti; :issue:`9424`.)
 
diff --git a/Lib/test/test_unittest/_test_warnings.py b/Lib/test/test_unittest/_test_warnings.py
index 5cbfb532ad050..08b846ee47e92 100644
--- a/Lib/test/test_unittest/_test_warnings.py
+++ b/Lib/test/test_unittest/_test_warnings.py
@@ -18,17 +18,6 @@ def warnfun():
 warnings.warn('rw', RuntimeWarning)
 
 class TestWarnings(unittest.TestCase):
- # unittest warnings will be printed at most once per type (max one message
- # for the fail* methods, and one for the assert* methods)
- def test_assert(self):
- self.assertEquals(2+2, 4)
- self.assertEquals(2*2, 4)
- self.assertEquals(2**2, 4)
-
- def test_fail(self):
- self.failUnless(1)
- self.failUnless(True)
-
 def test_other_unittest(self):
 self.assertAlmostEqual(2+2, 4)
 self.assertNotAlmostEqual(4+4, 2)
diff --git a/Lib/test/test_unittest/test_assertions.py b/Lib/test/test_unittest/test_assertions.py
index a0db3423b868a..6557104b81fc0 100644
--- a/Lib/test/test_unittest/test_assertions.py
+++ b/Lib/test/test_unittest/test_assertions.py
@@ -271,15 +271,6 @@ def testAssertDictEqual(self):
 r"\+ \{'key': 'value'\}$",
 r"\+ \{'key': 'value'\} : oops$"])
 
- def testAssertDictContainsSubset(self):
- with warnings.catch_warnings():
- warnings.simplefilter("ignore", DeprecationWarning)
-
- self.assertMessages('assertDictContainsSubset', ({'key': 'value'}, {}),
- ["^Missing: 'key'$", "^oops$",
- "^Missing: 'key'$",
- "^Missing: 'key' : oops$"])
-
 def testAssertMultiLineEqual(self):
 self.assertMessages('assertMultiLineEqual', ("", "foo"),
 [r"\+ foo$", "^oops$",
diff --git a/Lib/test/test_unittest/test_case.py b/Lib/test/test_unittest/test_case.py
index e000fe4f07240..fae0d1076da94 100644
--- a/Lib/test/test_unittest/test_case.py
+++ b/Lib/test/test_unittest/test_case.py
@@ -698,36 +698,6 @@ def testAssertIn(self):
 self.assertRaises(self.failureException, self.assertNotIn, 'cow',
 animals)
 
- def testAssertDictContainsSubset(self):
- with warnings.catch_warnings():
- warnings.simplefilter("ignore", DeprecationWarning)
-
- self.assertDictContainsSubset({}, {})
- self.assertDictContainsSubset({}, {'a': 1})
- self.assertDictContainsSubset({'a': 1}, {'a': 1})
- self.assertDictContainsSubset({'a': 1}, {'a': 1, 'b': 2})
- self.assertDictContainsSubset({'a': 1, 'b': 2}, {'a': 1, 'b': 2})
-
- with self.assertRaises(self.failureException):
- self.assertDictContainsSubset({1: "one"}, {})
-
- with self.assertRaises(self.failureException):
- self.assertDictContainsSubset({'a': 2}, {'a': 1})
-
- with self.assertRaises(self.failureException):
- self.assertDictContainsSubset({'c': 1}, {'a': 1})
-
- with self.assertRaises(self.failureException):
- self.assertDictContainsSubset({'a': 1, 'c': 1}, {'a': 1})
-
- with self.assertRaises(self.failureException):
- self.assertDictContainsSubset({'a': 1, 'c': 1}, {'a': 1})
-
- one = ''.join(chr(i) for i in range(255))
- # this used to cause a UnicodeDecodeError constructing the failure msg
- with self.assertRaises(self.failureException):
- self.assertDictContainsSubset({'foo': one}, {'foo': '\uFFFD'})
-
 def testAssertEqual(self):
 equal_pairs = [
 ((), ()),
@@ -1790,45 +1760,18 @@ def testAssertNoLogsYieldsNone(self):
 pass
 self.assertIsNone(value)
 
- def testDeprecatedMethodNames(self):
- """
- Test that the deprecated methods raise a DeprecationWarning. See #9424.
- """
- old = (
- (self.failIfEqual, (3, 5)),
- (self.assertNotEquals, (3, 5)),
- (self.failUnlessEqual, (3, 3)),
- (self.assertEquals, (3, 3)),
- (self.failUnlessAlmostEqual, (2.0, 2.0)),
- (self.assertAlmostEquals, (2.0, 2.0)),
- (self.failIfAlmostEqual, (3.0, 5.0)),
- (self.assertNotAlmostEquals, (3.0, 5.0)),
- (self.failUnless, (True,)),
- (self.assert_, (True,)),
- (self.failUnlessRaises, (TypeError, lambda _: 3.14 + 'spam')),
- (self.failIf, (False,)),
- (self.assertDictContainsSubset, (dict(a=1, b=2), dict(a=1, b=2, c=3))),
- (self.assertRaisesRegexp, (KeyError, 'foo', lambda: {}['foo'])),
- (self.assertRegexpMatches, ('bar', 'bar')),
- )
- for meth, args in old:
- with self.assertWarns(DeprecationWarning):
- meth(*args)
-
- # disable this test for now. When the version where the fail* methods will
- # be removed is decided, re-enable it and update the version
- def _testDeprecatedFailMethods(self):
- """Test that the deprecated fail* methods get removed in 3.x"""
- if sys.version_info[:2] < (3, 3):
- return
+ def testDeprecatedFailMethods(self):
+ """Test that the deprecated fail* methods get removed in 3.12"""
 deprecated_names = [
 'failIfEqual', 'failUnlessEqual', 'failUnlessAlmostEqual',
 'failIfAlmostEqual', 'failUnless', 'failUnlessRaises', 'failIf',
- 'assertDictContainsSubset',
+ 'assertNotEquals', 'assertEquals', 'assertAlmostEquals',
+ 'assertNotAlmostEquals', 'assert_', 'assertDictContainsSubset',
+ 'assertRaisesRegexp', 'assertRegexpMatches'
 ]
 for deprecated_name in deprecated_names:
 with self.assertRaises(AttributeError):
- getattr(self, deprecated_name) # remove these in 3.x
+ getattr(self, deprecated_name)
 
 def testDeepcopy(self):
 # Issue: 5660
diff --git a/Lib/test/test_unittest/test_loader.py b/Lib/test/test_unittest/test_loader.py
index c06ebb658d287..bbdfb247ebaad 100644
--- a/Lib/test/test_unittest/test_loader.py
+++ b/Lib/test/test_unittest/test_loader.py
@@ -5,25 +5,6 @@
 
 import unittest
 
-# Decorator used in the deprecation tests to reset the warning registry for
-# test isolation and reproducibility.
-def warningregistry(func):
- def wrapper(*args, **kws):
- missing = []
- saved = getattr(warnings, '__warningregistry__', missing).copy()
- try:
- return func(*args, **kws)
- finally:
- if saved is missing:
- try:
- del warnings.__warningregistry__
- except AttributeError:
- pass
- else:
- warnings.__warningregistry__ = saved
- return wrapper
-
-
 class Test_TestLoader(unittest.TestCase):
 
 ### Basic object tests
@@ -174,9 +155,8 @@ class NotAModule(object):
 self.assertEqual(list(suite), reference)
 
 
- # Check that loadTestsFromModule honors (or not) a module
+ # Check that loadTestsFromModule honors a module
 # with a load_tests function.
- @warningregistry
 def test_loadTestsFromModule__load_tests(self):
 m = types.ModuleType('m')
 class MyTestCase(unittest.TestCase):
@@ -195,126 +175,13 @@ def load_tests(loader, tests, pattern):
 suite = loader.loadTestsFromModule(m)
 self.assertIsInstance(suite, unittest.TestSuite)
 self.assertEqual(load_tests_args, [loader, suite, None])
- # With Python 3.5, the undocumented and unofficial use_load_tests is
- # ignored (and deprecated).
- load_tests_args = []
- with warnings.catch_warnings(record=False):
- warnings.simplefilter('ignore')
- suite = loader.loadTestsFromModule(m, use_load_tests=False)
- self.assertEqual(load_tests_args, [loader, suite, None])
-
- @warningregistry
- def test_loadTestsFromModule__use_load_tests_deprecated_positional(self):
- m = types.ModuleType('m')
- class MyTestCase(unittest.TestCase):
- def test(self):
- pass
- m.testcase_1 = MyTestCase
-
- load_tests_args = []
- def load_tests(loader, tests, pattern):
- self.assertIsInstance(tests, unittest.TestSuite)
- load_tests_args.extend((loader, tests, pattern))
- return tests
- m.load_tests = load_tests
- # The method still works.
- loader = unittest.TestLoader()
- # use_load_tests=True as a positional argument.
- with warnings.catch_warnings(record=True) as w:
- warnings.simplefilter('always')
- suite = loader.loadTestsFromModule(m, False)
- self.assertIsInstance(suite, unittest.TestSuite)
- # load_tests was still called because use_load_tests is deprecated
- # and ignored.
- self.assertEqual(load_tests_args, [loader, suite, None])
- # We got a warning.
- self.assertIs(w[-1].category, DeprecationWarning)
- self.assertEqual(str(w[-1].message),
- 'use_load_tests is deprecated and ignored')
-
- @warningregistry
- def test_loadTestsFromModule__use_load_tests_deprecated_keyword(self):
- m = types.ModuleType('m')
- class MyTestCase(unittest.TestCase):
- def test(self):
- pass
- m.testcase_1 = MyTestCase
-
- load_tests_args = []
- def load_tests(loader, tests, pattern):
- self.assertIsInstance(tests, unittest.TestSuite)
- load_tests_args.extend((loader, tests, pattern))
- return tests
- m.load_tests = load_tests
- # The method still works.
- loader = unittest.TestLoader()
- with warnings.catch_warnings(record=True) as w:
- warnings.simplefilter('always')
- suite = loader.loadTestsFromModule(m, use_load_tests=False)
- self.assertIsInstance(suite, unittest.TestSuite)
- # load_tests was still called because use_load_tests is deprecated
- # and ignored.
- self.assertEqual(load_tests_args, [loader, suite, None])
- # We got a warning.
- self.assertIs(w[-1].category, DeprecationWarning)
- self.assertEqual(str(w[-1].message),
- 'use_load_tests is deprecated and ignored')
-
- @warningregistry
- def test_loadTestsFromModule__too_many_positional_args(self):
- m = types.ModuleType('m')
- class MyTestCase(unittest.TestCase):
- def test(self):
- pass
- m.testcase_1 = MyTestCase
-
- load_tests_args = []
- def load_tests(loader, tests, pattern):
- self.assertIsInstance(tests, unittest.TestSuite)
- load_tests_args.extend((loader, tests, pattern))
- return tests
- m.load_tests = load_tests
- loader = unittest.TestLoader()
- with self.assertRaises(TypeError) as cm, \
- warnings.catch_warnings(record=True) as w:
- warnings.simplefilter('always')
- loader.loadTestsFromModule(m, False, 'testme.*')
- # We still got the deprecation warning.
- self.assertIs(w[-1].category, DeprecationWarning)
- self.assertEqual(str(w[-1].message),
- 'use_load_tests is deprecated and ignored')
- # We also got a TypeError for too many positional arguments.
- self.assertEqual(type(cm.exception), TypeError)
- self.assertEqual(
- str(cm.exception),
- 'loadTestsFromModule() takes 1 positional argument but 3 were given')
-
- @warningregistry
- def test_loadTestsFromModule__use_load_tests_other_bad_keyword(self):
- m = types.ModuleType('m')
- class MyTestCase(unittest.TestCase):
- def test(self):
- pass
- m.testcase_1 = MyTestCase
 
- load_tests_args = []
- def load_tests(loader, tests, pattern):
- self.assertIsInstance(tests, unittest.TestSuite)
- load_tests_args.extend((loader, tests, pattern))
- return tests
- m.load_tests = load_tests
- loader = unittest.TestLoader()
- with warnings.catch_warnings():
- warnings.simplefilter('ignore')
- with self.assertRaises(TypeError) as cm:
- loader.loadTestsFromModule(
- m, use_load_tests=False, very_bad=True, worse=False)
- self.assertEqual(type(cm.exception), TypeError)
- # The error message names the first bad argument alphabetically,
- # however use_load_tests (which sorts first) is ignored.
- self.assertEqual(
- str(cm.exception),
- "loadTestsFromModule() got an unexpected keyword argument 'very_bad'")
+ # In Python 3.12, the undocumented and unofficial use_load_tests has
+ # been removed.
+ with self.assertRaises(TypeError):
+ loader.loadTestsFromModule(m, False)
+ with self.assertRaises(TypeError):
+ loader.loadTestsFromModule(m, use_load_tests=False)
 
 def test_loadTestsFromModule__pattern(self):
 m = types.ModuleType('m')
diff --git a/Lib/test/test_unittest/test_program.py b/Lib/test/test_unittest/test_program.py
index 3fecbcda95fa3..3645bcf4b4356 100644
--- a/Lib/test/test_unittest/test_program.py
+++ b/Lib/test/test_unittest/test_program.py
@@ -461,14 +461,14 @@ def run_unittest(args):
 return stderr.decode()
 
 t = '_test_warnings'
- self.assertIn('Ran 7 tests', run_unittest([t]))
- self.assertIn('Ran 7 tests', run_unittest(['-k', 'TestWarnings', t]))
- self.assertIn('Ran 7 tests', run_unittest(['discover', '-p', '*_test*', '-k', 'TestWarnings']))
- self.assertIn('Ran 2 tests', run_unittest(['-k', 'f', t]))
- self.assertIn('Ran 7 tests', run_unittest(['-k', 't', t]))
- self.assertIn('Ran 3 tests', run_unittest(['-k', '*t', t]))
- self.assertIn('Ran 7 tests', run_unittest(['-k', '*test_warnings.*Warning*', t]))
- self.assertIn('Ran 1 test', run_unittest(['-k', '*test_warnings.*warning*', t]))
+ self.assertIn('Ran 5 tests', run_unittest([t]))
+ self.assertIn('Ran 5 tests', run_unittest(['-k', 'TestWarnings', t]))
+ self.assertIn('Ran 5 tests', run_unittest(['discover', '-p', '*_test*', '-k', 'TestWarnings']))
+ self.assertIn('Ran 1 test ', run_unittest(['-k', 'f', t]))
+ self.assertIn('Ran 5 tests', run_unittest(['-k', 't', t]))
+ self.assertIn('Ran 2 tests', run_unittest(['-k', '*t', t]))
+ self.assertIn('Ran 5 tests', run_unittest(['-k', '*test_warnings.*Warning*', t]))
+ self.assertIn('Ran 1 test ', run_unittest(['-k', '*test_warnings.*warning*', t]))
 
 
 if __name__ == '__main__':
diff --git a/Lib/test/test_unittest/test_runner.py b/Lib/test/test_unittest/test_runner.py
index 9e3a0a9ca08d6..d396f2bab5787 100644
--- a/Lib/test/test_unittest/test_runner.py
+++ b/Lib/test/test_unittest/test_runner.py
@@ -1262,8 +1262,6 @@ def get_parse_out_err(p):
 return [b.splitlines() for b in p.communicate()]
 opts = dict(stdout=subprocess.PIPE, stderr=subprocess.PIPE,
 cwd=os.path.dirname(__file__))
- ae_msg = b'Please use assertEqual instead.'
- at_msg = b'Please use assertTrue instead.'
 
 # no args -> all the warnings are printed, unittest warnings only once
 p = subprocess.Popen([sys.executable, '-E', '_test_warnings.py'], **opts)
@@ -1271,11 +1269,11 @@ def get_parse_out_err(p):
 out, err = get_parse_out_err(p)
 self.assertIn(b'OK', err)
 # check that the total number of warnings in the output is correct
- self.assertEqual(len(out), 12)
+ self.assertEqual(len(out), 10)
 # check that the numbers of the different kind of warnings is correct
 for msg in [b'dw', b'iw', b'uw']:
 self.assertEqual(out.count(msg), 3)
- for msg in [ae_msg, at_msg, b'rw']:
+ for msg in [b'rw']:
 self.assertEqual(out.count(msg), 1)
 
 args_list = (
@@ -1302,11 +1300,9 @@ def get_parse_out_err(p):
 with p:
 out, err = get_parse_out_err(p)
 self.assertIn(b'OK', err)
- self.assertEqual(len(out), 14)
+ self.assertEqual(len(out), 12)
 for msg in [b'dw', b'iw', b'uw', b'rw']:
 self.assertEqual(out.count(msg), 3)
- for msg in [ae_msg, at_msg]:
- self.assertEqual(out.count(msg), 1)
 
 def testStdErrLookedUpAtInstantiationTime(self):
 # see issue 10786
diff --git a/Lib/unittest/__init__.py b/Lib/unittest/__init__.py
index b8de8c95d6158..5bcbf834840b5 100644
--- a/Lib/unittest/__init__.py
+++ b/Lib/unittest/__init__.py
@@ -69,9 +69,6 @@ def testMultiply(self):
 # IsolatedAsyncioTestCase will be imported lazily.
 from .loader import makeSuite, getTestCaseNames, findTestCases
 
-# deprecated
-_TextTestResult = TextTestResult
-
 
 # Lazy import of IsolatedAsyncioTestCase from .async_case
 # It imports asyncio, which is relatively heavy, but most tests
diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py
index ffc8f19ddd38d..af8303333d408 100644
--- a/Lib/unittest/case.py
+++ b/Lib/unittest/case.py
@@ -1171,35 +1171,6 @@ def assertDictEqual(self, d1, d2, msg=None):
 standardMsg = self._truncateMessage(standardMsg, diff)
 self.fail(self._formatMessage(msg, standardMsg))
 
- def assertDictContainsSubset(self, subset, dictionary, msg=None):
- """Checks whether dictionary is a superset of subset."""
- warnings.warn('assertDictContainsSubset is deprecated',
- DeprecationWarning)
- missing = []
- mismatched = []
- for key, value in subset.items():
- if key not in dictionary:
- missing.append(key)
- elif value != dictionary[key]:
- mismatched.append('%s, expected: %s, actual: %s' %
- (safe_repr(key), safe_repr(value),
- safe_repr(dictionary[key])))
-
- if not (missing or mismatched):
- return
-
- standardMsg = ''
- if missing:
- standardMsg = 'Missing: %s' % ','.join(safe_repr(m) for m in
- missing)
- if mismatched:
- if standardMsg:
- standardMsg += '; '
- standardMsg += 'Mismatched values: %s' % ','.join(mismatched)
-
- self.fail(self._formatMessage(msg, standardMsg))
-
-
 def assertCountEqual(self, first, second, msg=None):
 """Asserts that two iterables have the same elements, the same number of
 times, without regard to order.
@@ -1363,27 +1334,6 @@ def assertNotRegex(self, text, unexpected_regex, msg=None):
 raise self.failureException(msg)
 
 
- def _deprecate(original_func):
- def deprecated_func(*args, **kwargs):
- warnings.warn(
- 'Please use {0} instead.'.format(original_func.__name__),
- DeprecationWarning, 2)
- return original_func(*args, **kwargs)
- return deprecated_func
-
- # see #9424
- failUnlessEqual = assertEquals = _deprecate(assertEqual)
- failIfEqual = assertNotEquals = _deprecate(assertNotEqual)
- failUnlessAlmostEqual = assertAlmostEquals = _deprecate(assertAlmostEqual)
- failIfAlmostEqual = assertNotAlmostEquals = _deprecate(assertNotAlmostEqual)
- failUnless = assert_ = _deprecate(assertTrue)
- failUnlessRaises = _deprecate(assertRaises)
- failIf = _deprecate(assertFalse)
- assertRaisesRegexp = _deprecate(assertRaisesRegex)
- assertRegexpMatches = _deprecate(assertRegex)
- assertNotRegexpMatches = _deprecate(assertNotRegex)
-
-
 
 class FunctionTestCase(TestCase):
 """A test case that wraps a test function.
diff --git a/Lib/unittest/loader.py b/Lib/unittest/loader.py
index 7e6ce2f224baf..eb18cd0b49cd2 100644
--- a/Lib/unittest/loader.py
+++ b/Lib/unittest/loader.py
@@ -93,30 +93,8 @@ def loadTestsFromTestCase(self, testCaseClass):
 loaded_suite = self.suiteClass(map(testCaseClass, testCaseNames))
 return loaded_suite
 
- # 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):
+ def loadTestsFromModule(self, module, *, pattern=None):
 """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)
diff --git a/Lib/unittest/runner.py b/Lib/unittest/runner.py
index cb452c7adefb7..6678adb6a7d81 100644
--- a/Lib/unittest/runner.py
+++ b/Lib/unittest/runner.py
@@ -200,15 +200,6 @@ def run(self, test):
 if self.warnings:
 # if self.warnings is set, use it to filter all the warnings
 warnings.simplefilter(self.warnings)
- # if the filter is 'default' or 'always', special-case the
- # warnings from the deprecated unittest methods to show them
- # no more than once per module, because they can be fairly
- # noisy. The -Wd and -Wa flags can be used to bypass this
- # only when self.warnings is None.
- if self.warnings in ['default', 'always']:
- warnings.filterwarnings('module',
- category=DeprecationWarning,
- message=r'Please use assert\w+ instead.')
 startTime = time.perf_counter()
 startTestRun = getattr(result, 'startTestRun', None)
 if startTestRun is not None:
diff --git a/Misc/NEWS.d/next/Library/2022-05-14-09-01-38.gh-issue-89325.ys-2BZ.rst b/Misc/NEWS.d/next/Library/2022-05-14-09-01-38.gh-issue-89325.ys-2BZ.rst
new file mode 100644
index 0000000000000..175869624f75d
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2022-05-14-09-01-38.gh-issue-89325.ys-2BZ.rst
@@ -0,0 +1,6 @@
+Removed many old deprecated :mod:`unittest` features:
+:class:`~unittest.TestCase` method aliases, undocumented and broken
+:class:`~unittest.TestCase` method ``assertDictContainsSubset``,
+undocumented :meth:`TestLoader.loadTestsFromModule
+<unittest.TestLoader.loadTestsFromModule>` parameter *use_load_tests*, and
+an underscored alias of the :class:`~unittest.TextTestResult` class.


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /