You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p>The class <code>unittest.TestCase</code> provides a range of assertion methods. As well as the general forms <code>assertTrue()</code> and <code>assertFalse()</code>
more specific forms such as <code>assertGreaterEquals()</code> and <code>assertNotIn()</code> are provided.
By using the more specific forms it is possible to get more precise and informative failure messages in the event of a test failing. This can speed up the debugging process.
</p>
</overview>
<recommendation>
<p>Replace all calls to <code>assertTrue()</code> and <code>assertFalse()</code> that do not provide a custom failure message with a more specific variant.
Alternatively, provide a tailored failure message using the <code>assertTrue(condition, message)</code> form.
</p>
</recommendation>
<example>
<p>In this example, <code>assertTrue()</code> and <code>assertFalse()</code> are used.</p>
<samplesrc="ImpreciseAssert.py" />
<p>
This will make it more difficult to determine what has gone wrong when <code>self.assertTrue(1 in [])</code> fails.
The failure message "AssertionError: False is not true" is not very helpful.
</p>
<p>A more useful error message can be generated by changing the asserts to the more specific forms as in the following example.</p>
<samplesrc="ImpreciseAssert2.py" />
<p>In this case, the failure message "AssertionError: 1 not found in []" is much more informative.</p>