pytest-unordered
pytest-unordered is a pytest plugin that provides a specialized `unordered()` matcher for asserting equality of collections (lists, sets, tuples, dictionaries) regardless of element order. It is currently at version 0.7.0 and typically releases new versions to support newer Python versions or add minor features.
Warnings
- breaking Support for Python 3.7 was dropped in version 0.6.0. If you are using Python 3.7, you must pin your `pytest-unordered` version.
- breaking The `unordered` matcher became a factory function in 0.4.0. Prior to this, `unordered` might have been used as a direct collection type (e.g., `UnorderedList`). This change simplifies usage but may break older tests.
- gotcha Default handling for `None` values within unordered collections was changed in version 0.3.0. This could subtly alter test results if your collections include `None` and you relied on the previous behavior.
Install
-
pip install pytest-unordered
Imports
- unordered
from pytest_unordered import unordered
- unordered_list
from pytest_unordered import unordered_list
- unordered_set
from pytest_unordered import unordered_set
- unordered_dict
from pytest_unordered import unordered_dict
Quickstart
import pytest
from pytest_unordered import unordered
def test_list_order_agnostic_equality():
actual_list = [1, 3, 2]
expected_list = [2, 1, 3]
assert actual_list == unordered(expected_list)
def test_dict_order_agnostic_equality():
actual_dict = {'a': 1, 'b': 2}
expected_dict = {'b': 2, 'a': 1}
assert actual_dict == unordered(expected_dict)