redundant-unittest-assert / W1503ΒΆ

Message emitted:

Redundant use of %s with constant value %r

Description:

The first argument of assertTrue and assertFalse is a condition. If a constant is passed as parameter, that condition will be always true. In this case a warning should be emitted. The same applies to assertEqual and assertNotEqual when both compared values are constants.

Problematic code:

import unittest


class DummyTestCase(unittest.TestCase):
    def test_dummy(self):
        self.assertTrue("foo")  # [redundant-unittest-assert]
        self.assertEqual(5, 5)  # [redundant-unittest-assert]

Correct code:

import unittest


class DummyTestCase(unittest.TestCase):
    def test_dummy(self):
        actual = "test_result"
        self.assertEqual(actual, "expected")

Additional details:

Directly asserting a string literal will always pass, and comparing two literals has an outcome that is already fixed by the source. The solution is to test something that could fail, or not assert at all.

For assertions using assert there are similar messages: assert-on-string-literal / W0129 and assert-on-tuple / W0199.

Related links:

Created by the stdlib checker.