Opened 9 years ago

Closed 9 years ago

Last modified 8 years ago

#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:2 by Tim Graham, 9 years ago

Component: UncategorizedCore (Other)
Patch needs improvement: set
Triage Stage: UnreviewedAccepted

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.

comment:3 by Jon Dufresne, 9 years ago

Patch needs improvement: unset

Incorporated suggestion. Thanks.

comment:4 by Tim Graham <timograham@…>, 9 years ago

Resolution: fixed
Status: newclosed

In 4f336f6:

Fixed #26747 -- Used more specific assertions in the Django test suite.

comment:5 by Tim Graham <timograham@…>, 9 years ago

In 13d60298:

[1.10.x] Fixed #26747 -- Used more specific assertions in the Django test suite.

Backport of 4f336f66523001b009ab038b10848508fd208b3b from master

comment:6 by Tim Graham <timograham@…>, 8 years ago

In 7b08e01c:

Refs #26747 -- Corrected a method name in tutorial05.

comment:7 by Tim Graham <timograham@…>, 8 years ago

In e5103de:

[1.10.x] Refs #26747 -- Corrected a method name in tutorial05.

Backport of 7b08e01c1358aedbd46fa26c91d4613d642ff609 from master

Note: See TracTickets for help on using tickets.
Back to Top