python - 由于应用程序尚未加载,Pytest 模型未导入

标签 python django django-rest-framework pytest

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.

有人可以帮我解决这个问题吗?感谢您的帮助。

最佳答案

pytest.ini 文件不知何故被错误地放置到另一个应用程序文件夹中,理想情况下应将其放置在 django 项目文件夹的根目录中。例如与 settings.py 并行

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

关于python - 由于应用程序尚未加载,Pytest 模型未导入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49947493/

相关文章:

django - LoginRequiredMixin 失败但用户已通过身份验证

rest - 是不是rest API路由按权限分开比较好?

python - Django : Custom save method with queryset

python - 如何从xpath获取绝对url?

python - Django 中的动态逻辑查询构建器

django - 如何在 Django 基于类的 View 中定义 transaction.atomic?

django - 在 Django Rest Framework 中制作通用过滤器

python - pandas DataFrame 类型转换

python - 如何使 Read plus (r+) 模式在 python 3 中工作?

python - Django Gunicorn 不加载静态文件