Я использую virtualenv с Python 3.11.9 и pytest 8.3.2
Код: Выделить всё
ImportError: No module named 'drf.settings'
pytest-django could not find a Django project (no manage.py file could be found). You must explicitly add your Django project to the Python path to have it picked up.
Код: Выделить всё
├── README.md
├── drf
│ ├── drf
│ │ ├── __init__.py
│ │ ├── production_settings.py
│ │ ├── settings.py
│ │ ├── urls.py
│ │ └── wsgi.py
│ ├── manage.py
│ └── tests
│ ├── __pycache__
│ │ └── test_auth.cpython-311-pytest-8.3.2.pyc
│ ├── factory_boy
│ │ ├── __pycache__
│ │ │ └── factory_models.cpython-311.pyc
│ │ └── factory_models.py
│ └── test_auth.py
├── drf-uwsgi.ini
├── pytest.ini
├── requirements.in
├── requirements.txt
Код: Выделить всё
[pytest]
DJANGO_SETTINGS_MODULE = drf.settings.py
python_files = test_*.py
- Я пытался добавить init.py в каталог тестов (кажется, не рекомендуется и не сработало)
- деактивируйте и повторно активируйте virtualenv
- измените drf.settings.py на drf. drf.settings, но ничего
- запустить pytest как модуль с тестами python -m pytest
- если я скопирую drf и попробую, то получу немного другую ошибку
Код: Выделить всё
ImportError: No module named 'drf.settings.py'; 'drf.settings' is not a package
pytest-django found a Django project in . (it contains manage.py) and added it to the Python path.
If this is wrong, add "django_find_project = false" to pytest.ini and explicitly manage your Python path.
Подробнее здесь: https://stackoverflow.com/questions/788 ... -directory