#26747 closed Cleanup/optimization (fixed)
Use more specific assertions in tests
| Reported by: | Jon Dufresne | Owned by: | nobody |
|---|---|---|---|
| Component: | Core (Other) | Version: | dev |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
Like #23620. I found more patterns that could use more specific assertions.
Example patterns:
self.assertEqual(expression, False) self.assertEqual(expression, True) self.assertEqual(expression, None) self.assertNotEqual(expression, None)
Will change these to:
self.assertFalse(expression) self.assertTrue(expression) self.assertIsNone(expression) self.assertIsNotNone(expression)
Python docs on assertions: https://docs.python.org/3/library/unittest.html#assert-methods
Change History (7)
comment:1 by , 9 years ago
| Has patch: | set |
|---|
comment:2 by , 9 years ago
| Component: | Uncategorized → Core (Other) |
|---|---|
| Patch needs improvement: | set |
| Triage Stage: | Unreviewed → Accepted |
As noted on the PR, I'm not convinced about the merits of assertTrue/False rather than assertEqual(val, True) since such the former pass if bool(val) is True/False which might be too loose.
Note:
See TracTickets
for help on using tickets.
https://github.com/django/django/pull/6760