The unittest module provides assertion methods specific to common types and operations. Both versions will test the same things, but
the dedicated one will provide a better error message, simplifying the debugging process.
This rule reports an issue when an assertion can be simplified by using a more specific function. The array below gives a list of assertions on which an issue will be raised, and which function should be used instead:
| Original | Dedicated |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import unittest
class SomeTest(unittest.TestCase):
def test_something(self):
x = foo()
y = bar()
self.assertFalse(x == y) # Noncompliant
self.assertTrue(x < y) # Noncompliant
class SomeTest(unittest.TestCase):
def test_something(self):
x = foo()
y = bar()
self.assertNotEqual(x, y)
self.assertLess(x, y)