Testdriven.io: Scalable FastAPI Applications on AWS. pytest not found main module

92 Views Asked by At

while i try to this course https://testdriven.io/courses/scalable-fastapi-aws/

i have some problems.

when i type

talk-booking/services/talk_booking $ poetry run pytest tests/integration

error raises

=============================================== 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 =================================================

my directory is

.
├── 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

i check health-check api work well. 127.0.0.1:8000

when i write test code in main.py, it works well.

if i resolve imporing issue, that will be perfect

1

There are 1 best solutions below

0
On

Your PYTHONPATH environment variable is probably not set. Try setting it like below:

export PYTHONPATH=$PWD