2015-09-18 86 views
0

我使用瓶框架,并想测试一个类(不烧瓶应用程序,我读过的测试文档here蟒蛇进口模块,多层次

我的文件夹结构如下图所示的画面,和init .py为每个文件夹。

enter image description here

但我尝试了所有之下,但他们没有工作。

from ... import grouper 

import reporting.dashboard.helpers.grouper 

import dashboard 
from dashboard.helpers.grouper import Grouper 

任何人都可以请给我如何包括

reporting/dashboard/helpers/grouper.py

在位于

我的测试模块的一些提示

reporting/tests/helpers/helper-test.py

非常感谢。

+0

你尝试'从... reporting.dashboard.helpers导入grouper'? – BrenBarn

+0

'helpers'目录是否有'__init __。py'? – thebjorn

+0

@BrenBarn我试过,但没有运气,“ValueError:尝试相对导入非包” – keypoint

回答

0

我确定了原因。这是因为文件夹“reporting”下的__init__.py不是空的,而是为Flask应用程序执行一些启动操作。当我使这个“__init__.py”一个空文件,导入成功使用

from reporting.dashboard.helpers.grouper import Grouper 

而且,蟒蛇-2.6可以无法识别“从xxx进口yyyClass”,而只是“进口xxxModule”

参考阅读: The import system