Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: cannot import name 'isclose'

I am running into a weird error when unit testing my Python module:

⅔ of the builds are passing normally, but one of them is failing to import isclose from the standard math library.

The error is reproduced below:

==================================== ERRORS ====================================
______________________ ERROR collecting tests/test_yau.py ______________________
ImportError while importing test module '/home/travis/build/Benjamin-Lee/squiggle/tests/test_yau.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
tests/test_yau.py:5: in <module>
    from math import isclose
E   ImportError: cannot import name 'isclose'
!!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!!!
=========================== 1 error in 0.29 seconds ============================
The command "pytest --cov=squiggle" exited with 2.

There is no file named math.py in the same directory (or at all in my package). What could be causing this?

Restarting the build multiple times has not fixed this error and it is only showing up in Python 3.4.

The full logs are accessible here.

like image 348
Benjamin Lee Avatar asked Jan 18 '26 11:01

Benjamin Lee


1 Answers

pytest has the function approx for testing approximate equality of two numbers, available for any python version. The assertion

assert math.isclose(a, b, rel_tol=rt, abs_tol=at)

could be thus replaced with

assert a == pytest.approx(b, rel=rt, abs=at)
like image 133
hoefling Avatar answered Jan 21 '26 01:01

hoefling



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!