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
TypeError with pytest.approx on nested dictionaries #3164
Comments
That seems expected to me. |
we should perhaps raise a better error message im reasonably sure that does anyone want to try? |
I think it'd be quite unusual to do additional type checking here (EAFP applies 😉). You'll probably get similar error messages if you do |
Recursively comparing dictionaries might get tricky I think. |
One can find an implementation of approx with support for nested dictionaries here: https://stackoverflow.com/a/56048692/1551810. It would be great if pytest could support this natively. |
its important to have a definition of whats expected wrt additional/missing keys wrt nested dictionaries, plus its not hard to put approx instances actually in dictionaries as well so we should find a clear spec of what approx should do, write it down in the docs and then go for it |
Hi! Any progress on this? It would help tremendously and save me from writing tons and tons of ugly boilerplate code for approximate comparisons of deeply nested dataclasses (or their dictifications) |
@Darkdragon84 nothing I'm aware of - if anything is happening, it would likely be noted in this issue. |
Btw I would vote for not reusing |
@nicoddemus we might want to set up a new pytest plugin for other assert helpers (pytest-unordered, and a few other items could go there for incubation) |
Understood. Good point @nicoddemus I will see what is out there. Thanks folks for the quick reaction 👍 |
deepdiff module is a good alternative for nested dictionaries
|
This can be fixed with a single line change: pytest/src/_pytest/python_api.py Line 90 in dfc910e
a == approx(x, rel=self.rel, abs=self.abs, nan_ok=self.nan_ok) for a, x in self._yield_comparisons(actual) will do the trick, along with removing the TypeError in ApproxMapping ( pytest/src/_pytest/python_api.py Line 307 in dfc910e
|
Pytest 3.3.2 on python 3.6.4 (Anaconda)
Ubuntu 16.04
The text was updated successfully, but these errors were encountered: