Overview

pytest 7.2, released on June 25, 2023, improves error reporting with clearer messages and more readable diffs.

Main Features

Improved error reporting

Error reports display more readable diffs for complex data structure comparisons (dicts, lists, objects).

python
def test_dict_comparison():
    expected = {'name': 'Alice', 'age': 30, 'city': 'Paris'}
    actual = {'name': 'Alice', 'age': 31, 'city': 'Lyon'}
    assert actual == expected
    # pytest shows a clear diff:
    # E   'age': 31 != 30
    # E   'city': 'Lyon' != 'Paris'

Faster test collection

Test collection is optimized, reducing discovery time on large projects with many test modules.

python
import pytest

@pytest.mark.fast
def test_simple_operation():
    assert 2 + 2 == 4

@pytest.mark.slow
def test_complex_operation():
    result = sum(range(1_000_000))
    assert result == 499999500000

# pytest -m fast  -> fast tests only
# pytest --collect-only  -> list without running

Sources