pytest-dev / pytest-dev/pytest
pytest_assertion plugin: representation of details failed in pytest.approx AttributeError: 'tuple' object has no attribute 'expected'.
Open
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 14.5k
- Forks
- 3.4k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 35
Description
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 listfrom the virtual environment you are using - pytest and operating system versions
- minimal example if possible
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the minimal test case with pytest 8.3.3, then inspect _pytest/python_api.py around line 343, where the reported AttributeError occurs. Trace the pytest.approx handling for a list of tuples and add or update a regression test for this input. Done means the assertion failure is reported without the plugin representation error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100