Closed
Description
I created this small pytest assert helper to compare lists/tuples ignoring item order:
https://gist.github.com/soxofaan/8e6512f765f0f0df697311c2561be57e
It's roughly assert sorted(actual) == sorted(expected)
, but with some added benefits:
- container type (list vs tuple) is also checked
- inspired by
pytest.approx
, to make it more explicit what the intention of the comparison is. You only have to use it in theexpected
object, you can leave theactual
object as is. It also works inside nested structures, e.g.assert {"foo": [1, 2, 3]} == {"foo": IgnoreOrder([3, 2, 1])}
Would it be worthwhile to create a PR for this?