2016-04-12 88 views
0

enter image description here导入错误:没有模块名为二进制与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 ================== 

我在做什么错?

回答

3

将当前目录添加到PYTHONPATH环境变量。

当你在Windows上:

$ set PYTHONPATH="." 

这将有助于py.test找到并导入模块。

检查py.test教程我看到,在“编写课程”部分,他们使用完全相同的技巧。因为你通常会测试已安装的Python模块(通常在项目根目录中使用setup.py并使用开发模式),并且无需使用PYTHONPATH就可以轻松导入,因此您无需执行此操作。

+0

谢谢你,工作!你能否给我一个参考你所讨论的“setup.py”? – user61629

+0

链接是[在您所关注的教程中](http://jeffknupp.com/blog/2013/08/16/open-sourcing-a-python-project-the-right-way/)。还有更多的页面(这不是小事)。我个人使用[pbr](http://docs.openstack.org/developer/pbr/)。假设你在git仓库工作,它工作得很好,并简化了打包成3行'setup.py'并且很好的读取ini格式的'setup.cfg'。 –

+0

非常感谢! – user61629

相关问题