Pytest更新后未连接到数据库

时间:2020-01-09 19:29:29

标签: python pytest pytest-django

Pytest因Attrs库而被迫更新后抛出大量错误

每个测试都有

之类的错误
ERROR             [  3%]Creating test database for alias 'default' ('test_dev')...

test setup failed
self = <django.contrib.gis.db.backends.postgis.base.DatabaseWrapper object at 0x108a614d0>

    def ensure_connection(self):
        """Guarantee that a connection to the database is established."""
        if self.connection is None:
            with self.wrap_database_errors:
>               self.connect()

venv/lib/python3.7/site-packages/django/db/backends/base/base.py:216: 

测试代码如下

def test_user_registration(client):
    url = reverse('auth-register')
    credentials = {
        'email': 'test@test.com',
        'password': 'localhost',
        'username': 'test@test.com',
        'firstName': 'Jane',
        'lastName': 'Doe'
    }
    response = client.json.post(url, json.dumps(credentials))
    assert response.status_code == 201
    expected_keys = ['jwt', 'user']
    user_expected_keys = [
        'confirmed', 'blocked', '_id', 'email', 'username', 'firstName',
        'lastName', 'role', 'createdAt', 'updatedAt', 'readarticles', 'id',
        'property'
    ]
    assert set(expected_keys) == response.data.keys()
    assert set(user_expected_keys) == response.data['user'].keys()

这是完整的跟踪信息,似乎是姿势连接上的错误,我确保数据库已启动,并且服务器运行没有任何问题= Pytes版本是5.0.0-让我知道还有什么要发表的内容

ERROR         [ 27%]
test setup failed
request = <SubRequest '_django_db_marker' for <Function test_get_list_of_sections>>

    @pytest.fixture(autouse=True)
    def _django_db_marker(request):
        """Implement the django_db marker, internal to pytest-django.

        This will dynamically request the ``db``, ``transactional_db`` or
        ``django_db_reset_sequences`` fixtures as required by the django_db marker.
        """
        marker = request.node.get_closest_marker("django_db")
        if marker:
            transaction, reset_sequences = validate_django_db(marker)
            if reset_sequences:
                request.getfixturevalue("django_db_reset_sequences")
            elif transaction:
                request.getfixturevalue("transactional_db")
            else:
>               request.getfixturevalue("db")

venv/lib/python3.7/site-packages/pytest_django/plugin.py:478: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

request = <SubRequest 'django_db_setup' for <TestCaseFunction test_create_super_user>>
django_test_environment = None
django_db_blocker = <pytest_django.plugin._DatabaseBlocker object at 0x10f9bb250>
django_db_use_migrations = True, django_db_keepdb = False
django_db_createdb = False, django_db_modify_db_settings = None

    @pytest.fixture(scope="session")
    def django_db_setup(
        request,
        django_test_environment,
        django_db_blocker,
        django_db_use_migrations,
        django_db_keepdb,
        django_db_createdb,
        django_db_modify_db_settings,
    ):
        """Top level fixture to ensure test databases are available"""
        from .compat import setup_databases, teardown_databases

        setup_databases_args = {}

        if not django_db_use_migrations:
            _disable_native_migrations()

        if django_db_keepdb and not django_db_createdb:
            setup_databases_args["keepdb"] = True

        with django_db_blocker.unblock():
            db_cfg = setup_databases(
>               verbosity=pytest.config.option.verbose,
                interactive=False,
                **setup_databases_args
            )
E           pytest.PytestDeprecationWarning: the `pytest.config` global is deprecated.  Please use `request.config` or `pytest_configure` (if you're a pytest plugin) instead.

venv/lib/python3.7/site-packages/pytest_django/fixtures.py:108: PytestDeprecationWarning

tests/integration/test_blogs.py::test_mark_an_article_as_read ERROR      [ 31%]
test setup failed
request = <SubRequest '_django_db_marker' for <Function test_mark_an_article_as_read>>

    @pytest.fixture(autouse=True)
    def _django_db_marker(request):
        """Implement the django_db marker, internal to pytest-django.

        This will dynamically request the ``db``, ``transactional_db`` or
        ``django_db_reset_sequences`` fixtures as required by the django_db marker.
        """
        marker = request.node.get_closest_marker("django_db")
        if marker:
            transaction, reset_sequences = validate_django_db(marker)
            if reset_sequences:
                request.getfixturevalue("django_db_reset_sequences")
            elif transaction:
                request.getfixturevalue("transactional_db")
            else:
>               request.getfixturevalue("db")

venv/lib/python3.7/site-packages/pytest_django/plugin.py:478: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

request = <SubRequest 'django_db_setup' for <TestCaseFunction test_create_super_user>>
django_test_environment = None
django_db_blocker = <pytest_django.plugin._DatabaseBlocker object at 0x10f9bb250>
django_db_use_migrations = True, django_db_keepdb = False
django_db_createdb = False, django_db_modify_db_settings = None

    @pytest.fixture(scope="session")
    def django_db_setup(
        request,
        django_test_environment,
        django_db_blocker,
        django_db_use_migrations,
        django_db_keepdb,
        django_db_createdb,
        django_db_modify_db_settings,
    ):
        """Top level fixture to ensure test databases are available"""
        from .compat import setup_databases, teardown_databases

        setup_databases_args = {}

        if not django_db_use_migrations:
            _disable_native_migrations()

        if django_db_keepdb and not django_db_createdb:
            setup_databases_args["keepdb"] = True

        with django_db_blocker.unblock():
            db_cfg = setup_databases(
>               verbosity=pytest.config.option.verbose,
                interactive=False,
                **setup_databases_args
            )
E           pytest.PytestDeprecationWarning: the `pytest.config` global is deprecated.  Please use `request.config` or `pytest_configure` (if you're a pytest plugin) instead.

venv/lib/python3.7/site-packages/pytest_django/fixtures.py:108: PytestDeprecationWarning

0 个答案:

没有答案