Vishal786btc
Vishal786btc

Reputation: 438

Pytest models not getting imported due Apps aren't loaded yet

nas_apps
    nas_apps
       -__init__.py
       -environments.py
       -settings.py
       -urls.py
       -wsgi.py
       -pytest.ini
    usecase1
       -conf
       -logs
       -management
       -migrations
       -services
       -templates
       -utils
           -__init__.py
           -apps.py
           -controllers.py
           -forms.py
           -models.py
           -serializers.py
           -urls.py
           -views.py
    usecase2
    usecase3
    tests
        -fixtures
        -conftest.py
        -input_data.json
        -test_usecase1.py

=============================================================== platform linux -- Python 3.5.2, pytest-3.4.1, py-1.5.2, pluggy-0.6.0

-- /home/.../Envs/venv/bin/python3 cachedir: .pytest_cache rootdir: /home/..../Desktop/dev2/NAS/nas_apps/tests, inifile: plugins: sanic-0.1.8, django-3.1.2, cov-2.5.1 collected 0 items / 1 errors

========================================================================================= ERRORS

__________________________________________________________________________ ERROR collecting test_maintenance.py ___________________________________________________________________________ test_usecase1.py:17: in from usecase1.services.db_helper import DbHelper ../usecase1/services/db_helper.py:16: in from .log_service import LogRunner ../usecase1/services/log_service.py:17: in class LogRunner: ../usecase1/services/log_service.py:18: in LogRunner _config_manager = ConfigManager() ../usecase1/utils/config.py:24: in init curr_app_dir = apps.get_app_config('usecase1').verbose_name.lower() /home/.../Envs/uscc01/lib/python3.5/site-packages/django/apps/registry.py:145: in get_app_config self.check_apps_ready() /home/.../Envs/uscc01/lib/python3.5/site-packages/django/apps/registry.py:127: in check_apps_ready raise AppRegistryNotReady("Apps aren't loaded yet.") E django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.

Can someone please help me resolve this? Appreciate your help.

Upvotes: 1

Views: 2463

Answers (4)

akash singh
akash singh

Reputation: 39

Add all the apps in setting.py:

Example:

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_user_agents',
'add_your_created_app_here',
]

Upvotes: -1

Vishal786btc
Vishal786btc

Reputation: 438

pytest.ini file was somehow got misplaced to another apps folder, which should ideally be placed in root directory of Django project folder. For example parallel to settings.py.

# Content of pytest.ini
[pytest]
DJANGO_SETTINGS_MODULE = nas_apps_proj.settings
python_files = tests.py test_*.py *_tests.py

Upvotes: 2

Marek Grác
Marek Grác

Reputation: 773

Previous solutions might work in some specific cases. In other ones, take a look if you have installed pytest-django that solved my issue. We were missing this dependency in our requirements.txt and tester has installed it manually.

Upvotes: 1

akash singh
akash singh

Reputation: 39

try this :
INSTALLED_APPS = [ # Rest framework 'django_filters',
 'django_apscheduler', 
 'rest_framework',
 'corsheaders', 
 # Project applications 
'ms_vlan_failover.apps.Usecase1Config',        
'maintenance_check.apps.Usecase2Config', 
'reporting.apps.Usecase1Config', 
# Django defaults 
'django.contrib.admin', 
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions', 
'django.contrib.messages',    
'django.contrib.staticfiles',
'usecase1',
'usecase2',
'usecase3', 
'tests',
 ]

Upvotes: -1

Related Questions