@@ -346,7 +346,7 @@ def list_should_not_contain_duplicates(self, list_, msg=None):
346
346
'%s found multiple times.' % seq2str (dupes ))
347
347
348
348
def lists_should_be_equal (self , list1 , list2 , msg = None , values = True ,
349
- names = None ):
349
+ names = None , ignore_order = False ):
350
350
"""Fails if given lists are unequal.
351
351
352
352
The keyword first verifies that the lists have equal lengths, and then
@@ -370,6 +370,10 @@ def lists_should_be_equal(self, list1, list2, msg=None, values=True,
370
370
need to be named. It is not necessary to name all of the indices. When
371
371
using a dictionary, keys can be either integers or strings that can be
372
372
converted to integers.
373
+
374
+ Optional ``ignore_order`` argument can be used to ignore the order of the
375
+ elements (element index) in the list while comparing two lists. If set to
376
+ true, element order will be ignored. This option is new in RF 3.2 now.
373
377
374
378
Examples:
375
379
| ${names} = | Create List | First Name | Family Name | Email |
@@ -380,13 +384,23 @@ def lists_should_be_equal(self, list1, list2, msg=None, values=True,
380
384
If the items in index 2 would differ in the above examples, the error
381
385
message would contain a row like ``Index 2 (email): [email protected] !=
382
386
387
+
388
+ | ${list1} = | Create List | apple | cherry | banana |
389
+ | ${list2} = | Create List | cherry | banana | apple |
390
+ | Lists Should Be Equal | ${list1} | ${list2} | ignore_order=True |
391
+
392
+ list index would be ignored while comparing two lists. Above two list
393
+ will be matched.
383
394
"""
384
395
self ._validate_lists (list1 , list2 )
385
396
len1 = len (list1 )
386
397
len2 = len (list2 )
387
398
default = 'Lengths are different: %d != %d' % (len1 , len2 )
388
399
_verify_condition (len1 == len2 , default , msg , values )
389
400
names = self ._get_list_index_name_mapping (names , len1 )
401
+ if ignore_order :
402
+ list1 = sorted (list1 )
403
+ list2 = sorted (list2 )
390
404
diffs = list (self ._yield_list_diffs (list1 , list2 , names ))
391
405
default = 'Lists are different:\n ' + '\n ' .join (diffs )
392
406
_verify_condition (diffs == [], default , msg , values )
0 commit comments