按照本教程https://flask.palletsprojects.com/en/1.1.x/#user-s-guide我正在学习烧瓶但是,当我试图运行pytest
时,我得到了这个错误:
(FlaskVenv) MacBook-Pro-de-Hugo:FlaskProject hugovillalobos$ pytest
ImportError while loading conftest '/Users/hugovillalobos/Documents/Code/FlaskProject/tests/conftest.py'.
tests/conftest.py:4: in <module>
from Flaskr import create_app
E ModuleNotFoundError: No module named 'Flaskr'
这是引发错误的模块(conftest.py
):
这是教程中所示的模块代码(唯一的区别是我的模块大写):
我认为我的文件位置可能有问题,但我正确地映射了教程项目布局:
我不知道我错过了什么。在
您可能需要在python中将pytest作为一个模块运行(它将当前目录添加到搜索路径). 我记得有过类似的情况,这就解决了我的问题:
来源:https://docs.pytest.org/en/latest/usage.html#calling-pytest-through-python-m-pytest
您可以从命令行通过Python解释器调用测试:
python-m pytest[…] 这几乎等同于直接调用命令行脚本pytest[…],只是通过python调用也会将当前目录添加到搜索路径. 在
相关问题 更多 >
编程相关推荐