Skip to content

pytest.approx fails to print representation of tuples #9917

@akitaev

Description

@akitaev

Hi,
This looks like a bug in pytest.approx

a = (1+0j, 2+0j)
b = (1, 2.2)

def test_ab():
assert a == pytest.approx(b, abs=0.01)

E AssertionError: assert ((1+0j), (2+0j)) == approx((1 ± 1....2 ± 1.0e-02))
E (pytest_assertion plugin: representation of details failed: /opt/anaconda3/envs/py310/lib/python3.10/site-packages/_pytest/python_api.py:331: TypeError: object of type 'ApproxScalar' has no len().
E Probably an object has a faulty repr.)

Converting the tuples to numpy arrays helps.

(pytest 7.1.2, python 3.10.4)

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: approxrelated to pytest.approx functiontopic: reportingrelated to terminal output and user-facing messages and errors

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions