python - 无法在我的单元测试文件夹中导入 python 函数
问题描述
我的项目结构如下:
我现在想在测试文件夹中添加一些 UT,特别是在 UT_data_handler.py 中。使用这个 UT 文件,我正在尝试导入我想要测试的函数,例如:
from binary.data_handler import extract_data_file, convert_all_data_to_dict
之后我收到以下错误:
> python UT_data_handler.py
Traceback (most recent call last):
File "UT_data_handler.py", line 3, in <module>
from binary.data_handler import extract_data_file, convert_all_data_to_dict
ImportError: No module named binary.data_handler
有人可以提供建议/解决方案吗?
解决方案
(一处)Python 在当前工作目录中查找导入的文件。所以尝试从那里执行文件:
$ python test/UT_data_handler.py
推荐阅读
- ios - ArcGis Runtime 100 保存图层以供离线访问
- java - 在Java中将具有毫秒的字符串转换为日期格式
- haskell - 使用 ScopedTypeVariables 约束 fmap 函数参数
- c# - 自定义控件中的 Xamarin BindableProperty
- bash - 为什么 read builtin 命令在 zsh 和 bash 上有不同的行为?
- angularjs - AngularJS HTML5 模式与 apache 上的 UI 路由器
- javascript - Google 图表:错误:第 0 行有 1 列,但必须有 2
- android - WhatsApp 聊天列表
- python - 将表单集中的字段添加到 add_error
- c# - 在不同平台之间切换