Skip to content
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

Problem mit Approx #5737

Closed
antonykamp opened this issue Aug 13, 2019 · 4 comments
Closed

Problem mit Approx #5737

antonykamp opened this issue Aug 13, 2019 · 4 comments

Comments

@antonykamp
Copy link

antonykamp commented Aug 13, 2019

Hey guy,

I have a little problem with the function approx. I use it alot in a project, but in one situation it looks like the code by this guy.

Here is the spesific file, the line of code at 853:
assert constr_value[0] == pytest.approx(0, 1e-5)

The error:

E           assert -1.758637679927233e-11 == 0 ± 1.0e-12
E            +  where 0 ± 1.0e-12 = <function approx at 0x000001BB36AF9400>(0, 1e-11)
E            +    where <function approx at 0x000001BB36AF9400> = pytest.approx

I'm using the pytest version 4.3.1 from Anaconda3 and win 10 and these are my packages.

@The-Compiler
Copy link
Member

I don't follow. You expect a value to be 0 ± 1.0e-12 but it is -1.758637679927233e-11 which is far smaller (i.e. further away from 0).

@antonykamp
Copy link
Author

I know and i don't want it. I expected a value 0 ± 1e-5 (see code line), but pytest ignores my decision and uses 1e-12

@kalekundert
Copy link
Contributor

I think the problem is that you specified a relative tolerance instead of an absolute tolerance, and anything relative to 0 is still 0. Try this instead:

assert constr_value[0] == pytest.approx(0, abs=1e-5)

The logic behind all of this is explained here: https://docs.pytest.org/en/latest/reference.html#pytest-approx

@antonykamp
Copy link
Author

Great! Now it works like expected. Thanks for your quick help. 👍

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

3 participants