classification
Title: unittest.TestCase.assertTrue return True even if the expr is False
Type: behavior Stage: resolved
Components: Tests Versions: Python 3.5
process
Status: closed Resolution: works for me
Dependencies: Superseder:
Assigned To: Nosy List: lee yummy, serhiy.storchaka, steven.daprano, zach.ware
Priority: normal Keywords:

Created on 2020-05-25 03:02 by lee yummy, last changed 2020-05-25 20:31 by zach.ware. This issue is now closed.

Files
File name Uploaded Description Edit
test_asserttrue.py steven.daprano, 2020-05-25 04:53
Messages (4)
msg369843 - (view) Author: lee yummy (lee yummy) Date: 2020-05-25 03:02
self.assertTrue(np.array_equal(x, y), "") # x.shape is [58, 139]

np.array_equal(x, y) is False, but `self.assertTrue(np.array_equal(x, y), "")` doesn't raise error.
msg369847 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2020-05-25 04:52
Works for me in 3.7. See attached file. Can you provide a minimal piece of code that demonstrates the bug?

Since Python 3.5 is now only accepting security fixes, and numpy is a third-party library, unless you can demonstrate this in a more recent version I think we should close this as "Works For Me".
msg369858 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2020-05-25 07:48
assertTrue() always returns None, but its returned value is irrelevant, because it is only used for its side effect.
msg369922 - (view) Author: Zachary Ware (zach.ware) * (Python committer) Date: 2020-05-25 20:31
`unittest.TestCase.assertTrue` is simple enough (the entire implementation is copied below) that there is almost no way for it to fail to raise some kind of exception when its first argument is not truthy:

    def assertTrue(self, expr, msg=None):
        """Check that the expression is true."""
        if not expr:
            msg = self._formatMessage(msg, "%s is not true" % safe_repr(expr))
            raise self.failureException(msg)

This basically hasn't changed in the 19 years since the unittest module was added (though variously at times named `assert_` or `failUnless`), so I'm going to go ahead and close the issue.
History
Date User Action Args
2020-05-25 20:31:34zach.waresetstatus: open -> closed

title: unittest.TestCase.asserTrue return True even if the expr is False -> unittest.TestCase.assertTrue return True even if the expr is False
nosy: + zach.ware

messages: + msg369922
resolution: works for me
stage: resolved
2020-05-25 07:48:57serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg369858
2020-05-25 04:53:16steven.dapranosetfiles: + test_asserttrue.py
2020-05-25 04:52:57steven.dapranosetmessages: + msg369847
2020-05-25 04:46:28steven.dapranosetfiles: - test_asserttrue.py
2020-05-25 04:46:07steven.dapranosetmessages: - msg369846
2020-05-25 04:44:38steven.dapranosetfiles: + test_asserttrue.py
nosy: + steven.daprano
messages: + msg369846

2020-05-25 03:02:45lee yummycreate