Skip to content

Commit 7b2e3c7

Browse files
author
Tang Chen
committed
Use assertItemsEqual() instead of assertListEqual()
assertListEqual() is order sensitive. So we need to sort the lists before we compare them. Use assertItemsEqual() instead is better. Change-Id: I9eaa98716c7401f5b099b007438acc916dae619b
1 parent 7608123 commit 7b2e3c7

1 file changed

Lines changed: 2 additions & 10 deletions

File tree

openstackclient/tests/common/test_parseractions.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,7 @@ def test_good_values(self):
9191
{'req1': 'aaa', 'req2': 'bbb'},
9292
{'req1': '', 'req2': ''},
9393
]
94-
# Need to sort the lists before comparing them
95-
key = lambda x: x['req1']
96-
expect.sort(key=key)
97-
actual.sort(key=key)
98-
self.assertListEqual(expect, actual)
94+
self.assertItemsEqual(expect, actual)
9995

10096
def test_empty_required_optional(self):
10197
self.parser.add_argument(
@@ -119,11 +115,7 @@ def test_empty_required_optional(self):
119115
{'req1': 'aaa', 'req2': 'bbb'},
120116
{'req1': '', 'req2': ''},
121117
]
122-
# Need to sort the lists before comparing them
123-
key = lambda x: x['req1']
124-
expect.sort(key=key)
125-
actual.sort(key=key)
126-
self.assertListEqual(expect, actual)
118+
self.assertItemsEqual(expect, actual)
127119

128120
def test_error_values_with_comma(self):
129121
self.assertRaises(

0 commit comments

Comments
 (0)