Skip to content
Discussion options

You must be logged in to vote

"Both work — assertEqual(add_numbers("2", 3), None) passes — but assertIsNone is the better choice, and here's why it's worth deviating from the TODO's literal wording:

  • Intent: assertIsNone(result) reads as "this returns None", which is the test's meaning. assertEqual(result, None) reads as "this equals None", which happens to be the same thing only because None is a singleton. Reviewers and graders read the first as fluency.
  • Failure messages: assertIsNone's failure output is purpose-built (None is not None plus the actual repr), while assertEqual's generic diff buries the point.
  • The habit generalizes: assertTrue(x) vs assertIs(True, ...), assertIn, assertRaises — the specific assertions…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by dab00gieman
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants