Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Django+;tox:应用程序不是';还没装呢_Python_Django_Testing_Pytest_Tox - Fatal编程技术网

Python Django+;tox:应用程序不是';还没装呢

Python Django+;tox:应用程序不是';还没装呢,python,django,testing,pytest,tox,Python,Django,Testing,Pytest,Tox,我正在迁移一个Django项目以使用Tox和pytest。我在运行tox时得到以下信息 _________________________________________ ERROR collecting fixtureless/tests/test_django_project/test_app/tests/test_factory.py _________________________________________ fixtureless/tests/test_django_projec

我正在迁移一个Django项目以使用Tox和pytest。我在运行tox时得到以下信息

_________________________________________ ERROR collecting fixtureless/tests/test_django_project/test_app/tests/test_factory.py _________________________________________
fixtureless/tests/test_django_project/test_app/tests/test_factory.py:10: in <module>
    from test_app.models import ModelOne, ModelTwo
fixtureless/tests/test_django_project/test_app/models.py:11: in <module>
    class ModelOne(models.Model):
.tox/py36-django21/lib/python3.6/site-packages/django/db/models/base.py:87: in __new__
    app_config = apps.get_containing_app_config(module)
.tox/py36-django21/lib/python3.6/site-packages/django/apps/registry.py:249: in get_containing_app_config
    self.check_apps_ready()
.tox/py36-django21/lib/python3.6/site-packages/django/apps/registry.py:132: in check_apps_ready
    raise AppRegistryNotReady("Apps aren't loaded yet.")
E   django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu_________________________________________
无固定装置/tests/test_django_项目/test_应用程序/tests/test_工厂。py:10:in
从测试应用程序模型导入模型一、模型二
fixtureless/tests/test_django_project/test_app/models.py:11:in
ModelOne类(models.Model):
.tox/py36-django21/lib/python3.6/site packages/django/db/models/base.py:87:in\uu new__
app\u config=apps.get\u包含app\u config(模块)
.tox/py36-django21/lib/python3.6/site packages/django/apps/registry.py:249:in-get_-containing_-app_-config
self.check_apps_ready()
.tox/py36-django21/lib/python3.6/site packages/django/apps/registry.py:132:in check\u apps\u ready
raise AppRegistryNotReady(“应用程序尚未加载。”)
E django.core.exceptions.AppRegistryNotReady:尚未加载应用程序。
这是我的毒物档案

[tox]
skipsdist = true
envlist =
    py{36,37}-django21,
    py{36,37}-django22,

# Add environment to use the default python3 installation
[testenv]
setenv =
    PYTHONDONTWRITEBYTECODE=1
    PYTHONPATH = {toxinidir}:{toxinidir}/fixtureless/tests/test_django_project
    DJANGO_SETTINGS_MODULE = settings.postgres
deps =
    pillow
    psycopg2
    pytest
    django21: Django>=2.1,<2.2
    django22: Django>=2.2,<2.3
commands = pytest
[tox]
skipsdist=true
环境清单=
py{36,37}-django21,
py{36,37}-django22,
#添加环境以使用默认的python3安装
[测试]
塞滕夫=
PYTHONDONTWRITEBYTECODE=1
PYTHONPATH={toxinidir}:{toxinidir}/fixtureless/tests/test_django_项目
DJANGO_SETTINGS_MODULE=SETTINGS.postgres
副总裁=
枕头
psycopg2
皮特斯特

django21:Django>=2.1,=2.2,Django不知道如何运行
pytest
风格的测试函数。Plain
pytest
也不提供django集成。你也可以

  • 编写自定义测试运行程序(一个简单的示例):

    并将应用程序配置为使用它,而不是默认的
    DiscoveryRunner

    # myapp/settings.py
    TEST_RUNNER = 'myapp.runner.PytestRunner'
    
    现在,
    python manage.py test
    将调用
    pytest
    ,而不是默认的
    unittest

  • 或者使用插件。将其添加到
    deps

    deps =
        ...
        pytest
        pytest-django
        ...
    
    这本身不提供与
    manage.py test
    的集成,但您可以通过
    pytest
    像往常一样调用测试:

    $ pytest --ds=myapp.settings
    ...
    
    该插件还提供了许多有用的装置来重新实现Django的测试助手(如
    RequestFactory
    Client
    等),因此您可以将
    unittest
    样式的测试类完整地移植到
    pytest
    样式的测试函数。有关配置详细信息和代码示例,请参阅
    pytest django


但是在dep列表中,
pytest-django
插件在哪里
pytest
本身并不能提供django测试运行程序,您需要一个能够提供该功能的插件。@hoefling这正是我的问题所在。如果你想发布答案,我很乐意为你赢得一些声誉。
$ pytest --ds=myapp.settings
...