#24714 closed Cleanup/optimization (fixed)
Use more specific assertions than assertEqual in tests
Reported by: | Alasdair Nicol | Owned by: | Alasdair Nicol |
---|---|---|---|
Component: | Core (Other) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
There are a few places in the tests where we are using self.assertEqual that could be more idiomatic.
self.assertEqual(None, x) # prefer self.assertIsNone(x) self.assertEqual(True, x in y) # prefer self.assertIn(x, y) self.assertEqual(True, x) # self.assertTrue(x) may be appropriate, but care is needed because it will pass for truthy values self.assertEqual(False, x) # self.assertFalse(x) may be appropriate, but care is needed because it will pass for falsey values self.assertEqual(True, x == y) # prefer self.assertEqual(x, y)
I found these using the following greps
grep -rI assertEqual.True grep -rI assertEqual.False grep -rI assertEqual.None
This is a similar tidy up to #23620
Change History (8)
comment:1 by , 10 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:2 by , 10 years ago
Has patch: | set |
---|
comment:3 by , 10 years ago
Component: | Uncategorized → Core (Other) |
---|---|
Patch needs improvement: | set |
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → Cleanup/optimization |
comment:4 by , 10 years ago
Description: | modified (diff) |
---|
As mentioned by Tim on the pull request, it is not always appropriate to use self.assertTrue
and self.assertFalse
, as these will pass for truthy and falsey values. I have updated the ticket description and pull request.
comment:5 by , 10 years ago
Description: | modified (diff) |
---|
comment:6 by , 10 years ago
Patch needs improvement: | unset |
---|---|
Summary: | Tidy up usage of assertEqual in tests → Use more specific assertions than assertEqual in tests |
Triage Stage: | Accepted → Ready for checkin |
Note:
See TracTickets
for help on using tickets.
Pull request https://github.com/django/django/pull/4570