Skip to content

pytest_assertion plugin: representation of details failed in pytest.approx AttributeError: 'tuple' object has no attribute 'expected'. #12839

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
3 of 4 tasks
graingert-coef opened this issue Sep 25, 2024 · 1 comment

Comments

@graingert-coef
Copy link

input:

import pytest


def sut():
    return [(1.0, 1.0)]


def test_approx():
    assert sut() == pytest.approx([(2.0, 2.0)])

output:

===================== test session starts ======================
platform darwin -- Python 3.12.6, pytest-8.3.3, pluggy-1.5.0
rootdir: /Users/thomas/projects/demo_assertion
collected 1 item

test_approx.py F                                         [100%]

=========================== FAILURES ===========================
_________________________ test_approx __________________________

    def test_approx():
>       assert sut() == pytest.approx([(2.0, 2.0)])
E       AssertionError: assert [(1.0, 1.0)] == approx([(2.0, 2.0)])
E
E         (pytest_assertion plugin: representation of details failed: /Users/thomas/.virtualenvs/demo_assertion/lib/python3.12/site-packages/_pytest/python_api.py:343: AttributeError: 'tuple' object has no attribute 'expected'.
E          Probably an object has a faulty __repr__.)

test_approx.py:9: AssertionError
=================== short test summary info ====================
FAILED test_approx.py::test_approx - AssertionError: assert [(1.0, 1.0)] == approx([(2.0, 2.0)])
====================== 1 failed in 0.01s =======================

pip list:

Package   Version
--------- -------
iniconfig 2.0.0
packaging 24.1
pip       24.2
pluggy    1.5.0
pytest    8.3.3

uname -a: Darwin Thomass-MacBook-Pro.local 23.6.0 Darwin Kernel Version 23.6.0: Mon Jul 29 21:14:04 PDT 2024; root:xnu-10063.141.2~1/RELEASE_ARM64_T8122 arm64

  • a detailed description of the bug or problem you are having
  • output of pip list from the virtual environment you are using
  • pytest and operating system versions
  • minimal example if possible
@RonnyPfannschmidt
Copy link
Member

We should raise a type error, this swim style usage is not intended

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants