Avoid misusing assertTrue in tests

assertTrue is not for comparing arguments. Consider assertEqual or others instead.

The purpose of the second argument of assertTrue is not for comparing equality with the first argument. It's actually the message that should be shown if the first argument is not truthy.

Calling assertTrue with two objects and expecting them to be compared will not work.

If our GitHub code review bot spots this issue in your pull request it gives this advice:

code-review-doctorbotsuggested changes just now
tests.py
1
+
class TestFeature(unittest.TestCase):
2
+
    def test_feature(self):
3
+
        self.assertTrue(value_one, value_two)
Suggested changes
-
        self.assertTrue(value_one, value_two)
+
        self.assertEqual(value_one, value_two)
Commit suggestion

assertTrue is not for comparing arguments. Consider assertEqual or others instead.

Read more
Update tests.py
We're your Python code review copilot. Get code improvements right in your pull request with our GitHub code review bot.

Configuring this check

Code Review Doctor will run this check by default. No configuration is needed but the check can be turned on/off using check code avoid-misusing-assert-true in your pyproject.toml file.

Read more about configuring Code Review Doctor.