Revert "bpo-45162: Revert "Remove many old deprecated unittest features"" by serhiy-storchaka · Pull Request #92556 · python/cpython · GitHub
Skip to content
Merged
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
55 changes: 7 additions & 48 deletions Doc/library/unittest.rst
39 changes: 39 additions & 0 deletions Doc/whatsnew/3.12.rst
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,45 @@ although there is currently no date scheduled for their removal.
Removed
=======

* Removed many old deprecated :mod:`unittest` features:
Comment thread
serhiy-storchaka marked this conversation as resolved.

- 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`:

Expand Down
3 changes: 1 addition & 2 deletions Doc/whatsnew/3.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`.)

Expand Down
11 changes: 0 additions & 11 deletions Lib/test/test_unittest/_test_warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 0 additions & 9 deletions Lib/test/test_unittest/test_assertions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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$",
Expand Down
69 changes: 6 additions & 63 deletions Lib/test/test_unittest/test_case.py
Loading