Проблема
При запуске pytest в вашем проекте вы видите следующее сообщение об ошибке:
pytest_import_error.txt
________ ERROR collecting test/test_Algorithms.py ________
ImportError while importing test module '/home/uli/dev/MyModule/test/test_Algorithms.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/lib/python3.10/importlib/__init__.py:126: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
test/test_Algorithms.py:3: in <module>
from MyModule.Algorithms import Algorithms
E ModuleNotFoundError: No module named 'MyModule'Решение
В вашем каталоге tests создайте __init__.py:
create_tests_init.sh
touch tests/__init__.pyВ маловероятном случае, если это не поможет, вам может потребоваться добавить корень проекта в ваш PYTHONPATH:
run_pytest_with_pythonpath.sh
PYTHONPATH=. pytests
Check out similar posts by category:
Python Модульное тестирование
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow