ImportError: No module named Binary with pytest
ImportError: No module named Binary with pytest
我正在处理 http://blog.thedigitalcatonline.com/blog/2015/05/13/python-oop-tdd-example-part1/#.Vw0NojFJJ9n。
当我尝试时:
$ py.test
============================= test session starts =============================
platform win32 -- Python 3.2.5, pytest-2.9.1, py-1.4.31, pluggy-0.3.1
rootdir: C:\envs\r3\binary, inifile:
plugins: capturelog-0.7
collected 0 items / 1 errors
=================================== ERRORS ====================================
____________________ ERROR collecting tests/test_binary.py ____________________
tests\test_binary.py:3: in <module>
import Binary
E ImportError: No module named Binary
================= 1 pytest-warnings, 1 error in 0.20 seconds ==================
我做错了什么?
将当前目录添加到 PYTHONPATH
环境变量。
正如你在 Windows:
$ set PYTHONPATH="."
这将有助于 py.test
查找和导入模块。
查看我看到的 py.test
教程,在 "Writing the class" 部分他们使用完全相同的技巧。
实际上,您不必这样做,因为您通常会针对已安装的 Python 模块进行测试(通常在项目根目录中使用 setup.py
并使用开发模式),并且它是可访问的无需使用 PYTHONPATH
.
即可轻松导入
我正在处理 http://blog.thedigitalcatonline.com/blog/2015/05/13/python-oop-tdd-example-part1/#.Vw0NojFJJ9n。
当我尝试时:
$ py.test
============================= test session starts =============================
platform win32 -- Python 3.2.5, pytest-2.9.1, py-1.4.31, pluggy-0.3.1
rootdir: C:\envs\r3\binary, inifile:
plugins: capturelog-0.7
collected 0 items / 1 errors
=================================== ERRORS ====================================
____________________ ERROR collecting tests/test_binary.py ____________________
tests\test_binary.py:3: in <module>
import Binary
E ImportError: No module named Binary
================= 1 pytest-warnings, 1 error in 0.20 seconds ==================
我做错了什么?
将当前目录添加到 PYTHONPATH
环境变量。
正如你在 Windows:
$ set PYTHONPATH="."
这将有助于 py.test
查找和导入模块。
查看我看到的 py.test
教程,在 "Writing the class" 部分他们使用完全相同的技巧。
实际上,您不必这样做,因为您通常会针对已安装的 Python 模块进行测试(通常在项目根目录中使用 setup.py
并使用开发模式),并且它是可访问的无需使用 PYTHONPATH
.