OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Tox+Django can't find package after Django upgrade

  • Thread starter Thread starter Cerin
  • Start date Start date
C

Cerin

Guest
I recently upgraded my Django dependency to 4.2, and now running tests via Tox fails with:

Code:
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:

Code:
[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:

Code:
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:

Code:
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?
<p>I recently upgraded my Django dependency to 4.2, and now running tests via Tox fails with:</p>
<pre><code>ModuleNotFoundError: No module named 'mypackage'
</code></pre>
<p>I haven't changed anything else and running Tox for Django 3.2 works fine.</p>
<p>My tox.ini looks like:</p>
<pre><code>[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
</code></pre>
<p>and my project structure looks like:</p>
<pre><code>myproject/
├── myproject/
│ ├── __init__.py
│ ├── tests/
│ │ ├── __init__.py
│ │ ├── settings.py
│ │ └── tests.py
│ └── ...
├── .tox/
├── .env/
├── .git/
├── setup.py
├── requirements.txt
├── requirements-test.txt
├── tox.ini
└── ...
</code></pre>
<p>and my test settings look like:</p>
<pre><code>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,
},
},
]
</code></pre>
<p>I don't see anything in the Django ~4 release notes that look like they would effect how Django detects packages.</p>
<p>I also checked in the generated <code>.tox/py38-django42/lib/python3.8/site-packages</code> and mypackage exists in there, so it should be detectable like any other package.</p>
<p>What am I doing wrong?</p>
 

Latest posts

Top