3 ms·
I'm no Python expert, but why does assertTrue() even accept two arguments?
by pc86 5y ago
I'm no Python expert, but why does assertTrue() even accept two arguments?
- js2 5y agoExplained later down in the post: > assertTrue also accepts a second argument, which is the custom error message to show if the first argument is not truthy. This call signature allows the mistake to be made and the test to pass and therefore possibly fail silently.
- guilherme-puida 5y agoThe second argument is the message that is displayed if the value is not truthy.
- cyberia23424 5y agoSecond arg is a string message to display when test fails
- 6LLvveMx2koXfwn 5y agoIndeed, from TFA; "assertTrue also accepts a second argument, which is the custom error message to show if the first argument is not truthy. This call signature allows the mistake to be made and the test to pass and therefore possibly fail silently."
- justinsaccount 5y agoThe 2nd argument is the 'msg' argument. With modern features in python you could change the signature to assertTrue(expr, *, msg=None) which would prevent that issue.
- d0mine 5y agoor just: assert expr, "custom message" though given the verbose api, it is ok to require the explicit msg kwarg (duplication in the tests is ok if it makes them more robust)