When I run pytest in my fastapi barebones app I get the error below. My test is in a file test_rms.py inside a tests folder. and I'm importing app from a main.py outside the tests folder. My file structure is also below. Why am I getting this error? Do I have to qualify my "from main import app" somehow? Thanks.
Contents of test_rms.py
from fastapi.testclient import TestClient
from main import app
client = TestClient(app)
def test_root():
response = client.get("/test")
assert response.status_code == 200
assert response.json() == {"message": "Hello World"}
Folder Structure:
ERROR:
___________________________________________________________________________________________________________________________________ ERROR collecting tests/test_rms.py ___________________________________________________________________________________________________________________________________
ImportError while importing test module 'C:\Scripting\Python\cct-api\tests\test_rms.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
C:\Users\azadmin\AppData\Local\Programs\Python\Python311\Lib\importlib\__init__.py:126: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
tests\test_rms.py:2: in <module>
from main import app
E ModuleNotFoundError: No module named 'main'