Skip to content

Confusing explanation for pytest.approx(subset) == superset on mappings #13722

Description

@bluetech

Consider this:

import pytest

def test_it():
    assert pytest.approx({"a": 1, "b": 2}) == {"a": 1, "b": 2, "c": 3}

Currently results in this output:

    def test_it():
>       assert pytest.approx({"a": 1, "b": 2}) == {"a": 1, "b": 2, "c": 3}
E       AssertionError: assert approx({'a': ... 2 ± 2.0e-06}) == {'a': 1, 'b': 2, 'c': 3}
E         
E         comparison failed. Mismatched elements: 0 / 2:
E         Max absolute difference: -inf
E         Max relative difference: -inf
E         Index | Obtained | Expected

The "comparison failed" messages doesn't actually show anything wrong (no mismatches), which is confusing.

I think it should give a message like ApproxSequence does when the lengths don't match:

E         Impossible to compare mappings with different sizes.
E         Lengths: 2 and 3

No activity

Activity on this issue will appear here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

topic: approxrelated to pytest.approx functiontopic: reportingrelated to terminal output and user-facing messages and errorstype: bugproblem that needs to be addressed

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions