I recently upgraded my Django dependency to 4.2, and now running tests via Tox fails with:
ModuleNotFoundError: No module named 'mypackage'
I haven’t changed anything else and running Tox for Django 3.2 works fine.
My tox.ini looks like:
[tox]
envlist = py{38}-django{32,42}
recreate = True
[testenv]
basepython =
py38: python3.8
deps =
-r{toxinidir}/requirements.txt
-r{toxinidir}/requirements-test.txt
django32: Django>=3.2,<3.3
django42: Django>=4.2,<5.0
-e . # Install the current package in editable mode
commands = django-admin.py test --traceback --settings=mypackage.tests.settings mypackage.tests.tests.TestCase
and my project structure looks like:
myproject/
├── myproject/
│ ├── __init__.py
│ ├── tests/
│ │ ├── __init__.py
│ │ ├── settings.py
│ │ └── tests.py
│ └── ...
├── .tox/
├── .env/
├── .git/
├── setup.py
├── requirements.txt
├── requirements-test.txt
├── tox.ini
└── ...
and my test settings look like:
import os
PROJECT_DIR = os.path.dirname(__file__)
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': ':memory:',
}
}
ROOT_URLCONF = 'mypackage.tests.urls'
INSTALLED_APPS = [
'django.contrib.auth',
'django.contrib.admin',
'django.contrib.contenttypes',
'django.contrib.messages',
'django.contrib.sessions',
'django.contrib.sites',
'mypackage',
'mypackage.tests',
'admin_steroids',
]
MEDIA_ROOT = os.path.join(PROJECT_DIR, 'media')
USE_TZ = True
TIME_ZONE = 'America/New_York'
USE_DEPRECATED_PYTZ = True
AUTH_USER_MODEL = 'auth.User'
SECRET_KEY = 'abc123'
SITE_ID = 1
BASE_SECURE_URL = 'https://localhost'
BASE_URL = 'http://localhost'
MIDDLEWARE_CLASSES = MIDDLEWARE = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.locale.LocaleMiddleware',
)
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
'%s/../templates' % PROJECT_DIR,
'%s/../static' % PROJECT_DIR,
],
'OPTIONS': {
'context_processors': [
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.template.context_processors.i18n',
'django.template.context_processors.media',
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.contrib.messages.context_processors.messages',
],
'loaders': [
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
],
'debug':
True,
},
},
]
I don’t see anything in the Django ~4 release notes that look like they would effect how Django detects packages.
I also checked in the generated .tox/py38-django42/lib/python3.8/site-packages
and mypackage exists in there, so it should be detectable like any other package.
What am I doing wrong?