【发布时间】:2021-02-27 20:52:34
【问题描述】:
抱歉,如果我要解决这个问题,但我对 python 还是很陌生,不能完全弄清楚问题出在哪里!我有一个简单的 Flask 应用程序,我正在尝试使用 pytest 编写测试。文件结构是这样的:
│── app.py
|── tests
│ ├── tests_app.py
我最初将 app.py 和 tests_app.py 放在同一级别,并且在测试通过时一切正常,但现在我将测试放在自己的文件夹中,我无法再无错误地导入应用程序。
我在 tests_app.py 中尝试了以下内容:
from app import app #this is what worked fine when app and tests were in the same folder
from ..app import app
from .. import app
并且 linting 错误是“尝试在顶级包之外进行相对导入”,当我运行 pytest 时,它显示“ImportError:尝试在没有已知父包的情况下进行相对导入”。
非常感谢!
附言我正在使用 Python 3.8.5
【问题讨论】:
-
This 可能会有所帮助。
标签: python python-3.x flask pytest