我在尝试学习本课程时遇到一些问题https://testdriven.io/courses/scalable-fastapi-aws/
当我输入时:
talk-booking/services/talk_booking $ poetry run pytest tests/integration
我收到以下错误:
=============================================== test session starts ================================================
platform darwin -- Python 3.11.1, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
rootdir: /Users/blarblar/Workspace/talk-booking/services/talk_booking
plugins: cov-4.0.0, anyio-3.6.2
collected 1 item / 1 error
====================================================== ERRORS ======================================================
___________________________ ERROR collecting tests/integration/test_web_app/test_main.py ___________________________
ImportError while importing test module '/Users/blarblar/Workspace/talk-booking/services/talk_booking/tests/integration/test_web_app/test_main.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/local/Cellar/[email protected]/3.11.1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/importlib/__init__.py:126: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
tests/integration/test_web_app/test_main.py:4: in <module>
from web_app.main import app
E ModuleNotFoundError: No module named 'web_app'
============================================= short test summary info ==============================================
ERROR tests/integration/test_web_app/test_main.py
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
================================================= 1 error in 0.29s =================================================
我的目录结构如下:
.
├── README.md
└── services
└── talk_booking
├── poetry.lock
├── pyproject.toml
├── tests
│ ├── __init__.py
│ └── integration
│ └── test_web_app
│ ├── __init__.py
│ └── test_main.py
└── web_app
├── __init__.py
└── main.py
我检查健康检查 api 工作良好。 127.0.0.1:8000
当我在main.py中编写测试代码时,效果很好。
如何解决此导入问题?
您的
PYTHONPATH
环境变量可能未设置。尝试如下设置:
export PYTHONPATH=$PWD