Open jmwebb opened 7 months ago
Hey @jmwebb... I've kind-of left the tests stranded since refreshing this stack, so thanks for looking at this.
I vaguely remember a similar issue on the main stack when I first started working on this. First question ... some of these weirder glitches on the .sh
files happen because of Windows vs Unix line-endings. Could that be related? After that, I'm not sure ... I'll have a look and see whether I can come up with anything.
Right, I've just run a full new build from cookiecutter
to see what happens. @jmwebb I'd be interested to know how you set things up? pytest
isn't one of the dependencies (sadly, when I did the migration from Poetry to Hatch, I must have left all the test requirements out). For the sake of speed, I simply added it to the main dependencies.
In test.sh
, the command to launch pytest
is:
pytest --cov=app --cov-report=term-missing app/tests "${@}"
But that fails. I'm not sure what either of the --cov
parameters does. Removing them results in the following error:
_______________________________________________________________________________________________________ ERROR collecting app/tests/crud/test_item.py _______________________________________________________________________________________________________
ImportError while importing test module '/app/app/tests/crud/test_item.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/local/lib/python3.11/importlib/__init__.py:126: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
app/tests/crud/test_item.py:4: in <module>
from app.schemas.item import ItemCreate, ItemUpdate
E ModuleNotFoundError: No module named 'app.schemas.item'
Which is not surprising, because the item
example doesn't exist in this build. So ... what I'm not replicating is you app.core
error.
Is this an error from this base stack, or is yours already your custom development?
Been having a ton of trouble running the
scripts/test-local.sh
as instructed in theREADME
. I keep running intoModulenotFoundError
issues inbackend/app/app/tests/conftest.py
I've confirmed the following are working:backend/app
to/app
as expected./app
is getting set as the Python path as expected.bash
'd into the backend container.sys.path
contains/app
as expected (I print it out while runningpytest -s
).However, no matter how I seem to run
pytest
(bash
'd into the backend service,docker compose run backend pytest
, or thetest-local.sh
script), I get the following error:When I try to append an extra
app.
to the imports (e.g.,from app.app.core.config import settings
, the error goes away, but then my regular backend service crashes (ModuleNotFoundErrorapp.app
). Clearly it is some difference between how pytest and running the service regularly handle imports.My file structure is the same as the template project: the
main.py
for FastAPI lives atbackend/app/app
, mypyproject.toml
lives atbackend/app
.I am running
pytest 7.1.3
,python 3.10
, and Mac OS 14.1.