A test calls an old alias of a unittest assertion, such as assertEquals, which Python 3.12 removed

tx0/python:removed-unittest-aliasdefaultwarningbug

What it finds

assertEquals, failUnless, assertRegexpMatches and the other old names of TestCase assertions were deprecated for years and removed in Python 3.12, where calling them raises AttributeError. Each has a current name, which the fix writes; the fix is safe. assertDictContainsSubset, removed at the same time, has no direct replacement and is reported without a fix. Reported are calls on self, unless the file defines a method of that name itself.

From the rule's source, removed_unittest_alias.rs.

Example from the rule's tests
import unittest class TestMath(unittest.TestCase):    def test_add(self):        self.assertEquals(1 + 1, 2)tx0 reports: assertEquals was removed in Python 3.12; its name is assertEqual        self.failUnless(True)tx0 reports: its name is assertTrue        self.assertDictContainsSubset({}, {})tx0 reports: assertDictContainsSubset was removed in Python 3.12; compare the items instead        self.assertEqual(1, 1)        other.assertEquals(1, 1)
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:

tx0.toml
[rules]
"tx0/python:removed-unittest-alias" = "off"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

# tx0: ignore[tx0/python:removed-unittest-alias] reason="..."

tx0 explain tx0/python:removed-unittest-alias shows the same in the terminal. Found a false positive? Report it.