Hacker News new | ask | show | jobs
by njharman 1582 days ago
Huh? Seems super clear to me that "assertTrue" is asserting Truthyness and not equality. It's right there in the method name! And if you don't know "True" means Truthyness in Python, they you don't know the basics of Python.

A reviewer should catch this error easily. I kind of think many don't give much attention to unittests when reviewing. Which is bad. Good unittests are far harder to write than good code.

There's much more subtle errors of this class (False Negatives / always pass).

2 comments

Given that this is a not uncommon mistake, despite the name, indicates that people make mistakes. They don't read. They're in a hurry. They see what they want to see.

The fix isn't to blame people for making mistakes. It's to figure out a design that doesn't allow this mistake to happen in the first place.

For example, the method could (today) require the second argument to be a keyword argument. This is also something a good linter should be able to warn on.

edit: rikatee and I wrote essentially the same reply at the same time. :-)

Agreed in perfect world, but unfortunately any process that involves humans will involve human error.

We do code review because we expect human error when the code was written by a human, but then we also expect not human error when the code is being read (reviewed) by a human? Any process that expects zero human error will always fail.

That's where linters add value: they allow devs to do what humans are good at (the creative complex and interesting stuff) while the bots do what bots are good at (the boring repetitive stuff)