【发布时间】:2017-11-25 12:03:58
【问题描述】:
我发现了一些类似的问题,但并没有完全解决我的问题(例如PATH issue with pytest 'ImportError: No module named YadaYadaYada')
我的项目结构如下:
MyApp
|
+--MyApp
| |
| +--__init__.py
| +--app.py
| +--config.py
|
+--tests
|
+--__init__.py
+--test_app.py
在我的 test_app.py 中,我导入 app.py,效果很好。
from MyApp import app
但在 app.py 中我像这样导入 config.py。
import config
通过此设置,我可以运行应用程序模块,但 pytest 无法导入“配置”并引发:
ImportError: No module named 'config'
当我将 app.py 中的 import 语句更改为时,pytest 成功:
from MyApp import config
但是,当我尝试运行应用程序时出现错误:
ImportError: No module named 'MyApp'
通过阅读其他问题,我确信 PYTHONPATH 有问题,我只是不知道如何解决这个问题。
【问题讨论】:
标签: python flask pytest importerror pythonpath