You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 the expected object, you can leave the actual object as is. It also works inside nested structures, e.g.
I like the idea; often one goes and uses a sorted() call, but that's not ideal because as you mention, it doesn't check the container type. Also using it inside nested structures is a plus.
Ahh indeed, we discussed this before and pytest-unordered was created because of that, although I'm not sure pytest-unordered also checks the types of the sequences being compared...
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: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.Would it be worthwhile to create a PR for this?
The text was updated successfully, but these errors were encountered: