How to assert two list contain the same elements in Python? [duplicate]

When writing test cases, I often need to assert that two list contain the same elements without regard to their order.

I have been doing this by converting the lists to sets.

Is there any simpler way to do this?

EDIT:

As @MarkDickinson pointed out, I can just use TestCase.assertItemsEqual.

Notes that TestCase.assertItemsEqual is new in Python2.7.
If you are using an older version of Python, you can use unittest2 – a backport of new features of Python 2.7.

5 Answers
5

Leave a Comment