Q:

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.

A:

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)

A:

As we can tell from the linked "full log", you're running Python 3.4.6.

$ python --version
Python 3.4.6

The math.isclose function was introduced in Python 3.5, which is why you cannot import it. Either install a later version of Python (ie. 3.5+), or define your own isclose function, the math module's is defined almost like the following:
def isclose(a, b, rel_tol=1e-9, abs_tol=0.0):
    return abs(a-b) <= max(rel_tol * max(abs(a), abs(b)), abs_tol)

# tests:
print(0.1 + 0.2)
print(0.1 + 0.2 == 0.3)
print(isclose(0.1 + 0.2, 0.3))

# outputs:

0.30000000000000004
False
True

a and b: are the two values to be tested to relative closeness
rel_tol: is the relative tolerance -- it is the amount of error
  allowed, relative to the larger absolute value of a or b. For example,
  to set a tolerance of 5%, pass rel_tol=0.05. The default tolerance is
  1e-9, which assures that the two values are the same within about 9
  decimal digits. rel_tol must be greater than 0.0
abs_tol: is a minimum absolute tolerance level -- useful for
  comparisons near zero.

