pytest-dev / pytest-dev/pytest
TypeError with pytest.approx on nested dictionaries
Open
Nobody has claimed this yet.
topic: approx
type: enhancement
- Dominant language
- Python
- Stars
- 14.5k
- Forks
- 3.4k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 35
Description
{'a': {'b': 0.2 + 0.1}} == pytest.approx({'a': {'b': 0.3}})
~/.conda/lib/python3.6/site-packages/_pytest/python_api.py in __eq__(self, actual)
195 # other or not. The abs() calls are for compatibility with complex
196 # numbers.
--> 197 if math.isnan(abs(self.expected)):
198 return self.nan_ok and math.isnan(abs(actual))
199
TypeError: bad operand type for abs(): 'dict'
Pytest 3.3.2 on python 3.6.4 (Anaconda)
Ubuntu 16.04
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 in _pytest/python_api.py around eq line 197 and reproduce the nested-dictionary comparison shown in the issue. Review the existing pytest.approx behavior and relevant tests before determining the expected comparison; done means the example no longer raises a TypeError and the intended result is covered by a test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100