pytest-clarity

1.0.1 · active · verified Tue Apr 14

pytest-clarity is a pytest plugin that provides an alternative, colourful diff output for failing assertions. Inspired by the Ward test framework, it aims to significantly improve the readability of assertion errors by showing clear, unified, coloured diffs. The current version is 1.0.1, last released in June 2021. It is a stable plugin with infrequent updates as its core functionality is well-defined and stable.

Warnings

Install

Imports

Quickstart

Install the plugin, then run your pytest tests with the `-vv` (very verbose) option. pytest-clarity will automatically enhance the output of failing assertions with colourful diffs. You can also customize diff width and symbolism.

# Save this to a file, e.g., test_example.py
def test_dict_failure():
    expected = {'a': 1, 'b': 2, 'c': 3}
    actual = {'a': 1, 'b': 99, 'd': 4}
    assert expected == actual

# Run pytest with verbose output to enable pytest-clarity
# In your terminal:
# pytest -vv

view raw JSON →