Issue
I am using pytest-django for the unit test cases for my django app. I have created pytest.ini in the root directory (same level as manage.py) with the following configs:
[pytest]
DJANGO_SETTINGS_MDOULE = mysite.settings
python_files = tests.py test_*.py *_tests.py
addopts = --reuse-db
Whenever I run command pytest in my root directory, it is giving me the following error:
ImportError while loading conftest '/Users/aakash/Desktop/experiments/repos/organonconnect/conftest.py'.
conftest.py:4: in <module>
from django.contrib.auth.models import User, Group
../venv/lib/python3.7/site-packages/django/contrib/auth/models.py:2: in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
../venv/lib/python3.7/site-packages/django/contrib/auth/base_user.py:47: in <module>
class AbstractBaseUser(models.Model):
../venv/lib/python3.7/site-packages/django/db/models/base.py:103: in __new__
app_config = apps.get_containing_app_config(module)
../venv/lib/python3.7/site-packages/django/apps/registry.py:252: in get_containing_app_config
self.check_apps_ready()
../venv/lib/python3.7/site-packages/django/apps/registry.py:134: in check_apps_ready
settings.INSTALLED_APPS
../venv/lib/python3.7/site-packages/django/conf/__init__.py:79: in __getattr__
self._setup(name)
../venv/lib/python3.7/site-packages/django/conf/__init__.py:64: in _setup
% (desc, ENVIRONMENT_VARIABLE))
E django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
However whenever I run pytest --ds=mysite.settings
, it works fine but without the configs mentioned in pytest.ini.
I have created a conftest.py at the same level as pytest.ini and I am using Python 3.7.7, pytest-5.4.1, py-1.8.1, pluggy-0.13.1
What am I doing wrong? Any help would be appreciated. Thanks in advance!
Solution
django_find_project = True
Add this to your pytest.ini
.
EDIT:
It looks like you have spelled DJANGO_SETTINGS_MODULE
wrong in your pytest.ini
. Please fix it.
Answered By - IgnisDa
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.