News for hackers. Stuff that matters.
Re:3 percent of Python codebases we checked had silently fai... by pc86 on Wednesday February 16, 2022 @09:51AM (#30360677)
I'm no Python expert, but why does assertTrue() even accept two arguments?
Re:3 percent of Python codebases we checked had silently fai... by js2 on Wednesday February 16, 2022 @09:56AM (#30360749)
Explained 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.

Re:3 percent of Python codebases we checked had silently fai... by justinsaccount on Wednesday February 16, 2022 @10:09AM (#30360916)
The 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.
Re:3 percent of Python codebases we checked had silently fai... by d0mine on Wednesday February 16, 2022 @12:39PM (#30362993)
or 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)
Re:3 percent of Python codebases we checked had silently fai... by guilherme-puida on Wednesday February 16, 2022 @09:54AM (#30360721)
The second argument is the message that is displayed if the value is not truthy.
Re:3 percent of Python codebases we checked had silently fai... by cyberia23424 on Wednesday February 16, 2022 @09:55AM (#30360733)
Second arg is a string message to display when test fails
Re:3 percent of Python codebases we checked had silently fai... by 6LLvveMx2koXfwn on Wednesday February 16, 2022 @10:00AM (#30360821)
Indeed, 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."