Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#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 Alasdair Nicol)

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 Alasdair Nicol, 9 years ago

Owner: changed from nobody to Alasdair Nicol
Status: newassigned

comment:2 by Alasdair Nicol, 9 years ago

Has patch: set

comment:3 by Tim Graham, 9 years ago

Component: UncategorizedCore (Other)
Patch needs improvement: set
Triage Stage: UnreviewedAccepted
Type: UncategorizedCleanup/optimization

comment:4 by Alasdair Nicol, 9 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 Alasdair Nicol, 9 years ago

Description: modified (diff)

comment:6 by Tim Graham, 9 years ago

Patch needs improvement: unset
Summary: Tidy up usage of assertEqual in testsUse more specific assertions than assertEqual in tests
Triage Stage: AcceptedReady for checkin

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

Resolution: fixed
Status: assignedclosed

In eaeea6f9:

Fixed #24714 -- Used more specific assertions than assertEqual in tests.

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

In c37eb3c:

[1.8.x] Fixed #24714 -- Used more specific assertions than assertEqual in tests.

Backport of eaeea6f94701547ce1b50dbcf5cf71460e9e4c91 from master

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