gpt4 book ai didi

python - 导入错误 : cannot import name 'isclose'

转载 作者:太空宇宙 更新时间:2023-11-04 07:29:16 26 4
gpt4 key购买 nike

我在对我的 Python 模块进行单元测试时遇到了一个奇怪的错误:

⅔ 的构建正常通过,但其中一个无法从标准 math 库导入 isclose

错误重现如下:

==================================== 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.

在同一目录(或我的包中根本没有)中没有名为 math.py 的文件。可能是什么原因造成的?

多次重新启动构建并没有修复这个错误,它只出现在 Python 3.4 中。

完整日志可访问here .

最佳答案

pytest 具有函数 approx用于测试两个数字的近似相等性,适用于任何 python 版本。断言

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

因此可以替换为

assert a == pytest.approx(b, rel=rt, abs=at)

关于python - 导入错误 : cannot import name 'isclose' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51220068/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com