You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
=================================== test session starts ===================================
platform linux -- Python 3.11.6, pytest-7.4.0, pluggy-1.2.0
rootdir: /media/600GB/Projects/python-projects/oneproject
collected 0 items / 1 error
========================================= ERRORS ==========================================
___________________________ ERROR collecting tests/test_main.py ___________________________
ImportError while importing test module '/media/600GB/Projects/python-projects/oneproject/tests/test_main.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/lib/python3.11/importlib/__init__.py:126: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
tests/test_main.py:1: in <module>
from fastapi.testclient import TestClient
E ModuleNotFoundError: No module named 'fastapi'
================================= short test summary info =================================
ERROR tests/test_main.py
!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!
==================================== 1 error in 0.20s =====================================
Workarounds
I tried creating another project and following the above steps and that is also showing this error. And this is not only the issue with fastapi but also importing any other package.
(oneproject-py3.11) bakar@bakar:/media/600GB/Projects/python-projects/oneproject$ poetry -vvv run pytest
Loading configuration file /home/bakar/.config/pypoetry/config.toml
Using virtualenv: /home/bakar/.cache/pypoetry/virtualenvs/oneproject-UtT7gf21-py3.11
=================================== test session starts ===================================
platform linux -- Python 3.11.6, pytest-7.4.0, pluggy-1.2.0
rootdir: /media/600GB/Projects/python-projects/oneproject
collected 0 items / 1 error
========================================= ERRORS ==========================================
___________________________ ERROR collecting tests/test_main.py ___________________________
ImportError while importing test module '/media/600GB/Projects/python-projects/oneproject/tests/test_main.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/lib/python3.11/importlib/__init__.py:126: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
tests/test_main.py:1: in<module>
from fastapi.testclient import TestClient
E ModuleNotFoundError: No module named 'fastapi'
================================= short test summary info =================================
ERROR tests/test_main.py
!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!
==================================== 1 error in 0.09s =====================================
The text was updated successfully, but these errors were encountered:
Description
When writing test file inside tests folder, the module not mount error is showing, but I have the package installed and working in main.py.
Folder Structure
pyproject.toml
main.py
When running this code with poetry its working fine
Test File Code (test_main.py)
Command to run the test
poetry run pytest
Error on terminal
Workarounds
I tried creating another project and following the above steps and that is also showing this error. And this is not only the issue with fastapi but also importing any other package.
Poetry Installation Method
pipx
Operating System
Ubuntu 23.10
Poetry Version
Poetry (version 1.8.2)
Poetry Configuration
Python Sysconfig
Example pyproject.toml
Poetry Runtime Logs
The text was updated successfully, but these errors were encountered: