python 多级导入模块

python import module multi-levels

我正在使用 Flask 框架并想测试单个 class(不是 Flask 应用程序,我已经阅读了测试文档 here

我的文件夹结构如下图,每个文件夹都有init.py

但我尝试了以下所有方法,但其中 none 有效。

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

?

非常感谢。

我已经确定了原因。因为文件夹"reporting"下的__init__.py不是空的,而是在对Flask app做一些启动操作。当我将此“__init__.py”设为空文件时,使用

导入成功
from reporting.dashboard.helpers.grouper import Grouper

另外,python-2.6可能不识别"from xxx import yyyClass",但只能"import xxxModule"

参考阅读: The import system