pytest-unordered

0.7.0 · active · verified Thu Apr 09

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

Install

Imports

Quickstart

This quickstart demonstrates how to use the `unordered()` matcher within pytest to assert equality of lists and dictionaries where the order of elements or keys does not matter. Save this as a Python file (e.g., `test_order.py`) and run `pytest`.

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)

view raw JSON →