Testdriven.io:AWS 上的可扩展 FastAPI 应用程序。 pytest 找不到主模块

问题描述 投票:0回答:1

当我尝试学习本课程时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 中编写测试代码时,效果很好。

如果我解决了导入问题,那就完美了

import module pytest fastapi testdriven.io
1个回答
0
投票

您的 PYTHONPATH 环境变量可能未设置。尝试如下设置 -

导出 PYTHONPATH=$PWD

© www.soinside.com 2019 - 2024. All rights reserved.