Opened 10 years ago

Last modified 10 years ago

#24714 closed Cleanup/optimization

Tidy up usage of assertEqual in tests — at Version 5

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 (5)

comment:1 by Alasdair Nicol, 10 years ago

Owner: changed from nobody to Alasdair Nicol
Status: newassigned

comment:2 by Alasdair Nicol, 10 years ago

Has patch: set

comment:3 by Tim Graham, 10 years ago

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

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

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top