Skip to content

Django setup_databases call signature change post 3.1 causes test setup to fail #858

Closed
@hugorodgerbrown

Description

@hugorodgerbrown

In the Django dev branch the django.test.utils.setup_databases function signature has changed, and this breaks the setup of tests:

The cause of this is a change in the method signature:

- def setup_databases(verbosity, interactive, keepdb=False, debug_sql=False, parallel=0, aliases=None, **kwargs):
+ def setup_databases(verbosity, interactive, *, time_keeper, keepdb=False, debug_sql=False, parallel=0, aliases=None):

Steps to reproduce:

Take any existing, working Django test suite, and run against latest dev commit - e.g. the djangomaster in the following tox.ini:

[testenv]
deps =
    pytest
    pytest-django
    django30: Django>=3.0,<3.1
    django31: Django>=3.1,<3.2
    djangomaster: https://github.com/django/django/archive/master.tar.gz

Expected outcome

Tests will run against master as they do for 3.0, 3.1 etc.

Actual outcome

All tests fail, at database setup:

________________________________________________ ERROR at setup of SettingsFunctionTests.test_get_settings ________________________________________________

request = <SubRequest '_django_setup_unittest' for <TestCaseFunction test_auto_sync>>
django_db_blocker = <pytest_django.plugin._DatabaseBlocker object at 0x106a02a30>

    @pytest.fixture(autouse=True, scope="class")
    def _django_setup_unittest(request, django_db_blocker):
        """Setup a django unittest, internal to pytest-django."""
        if not django_settings_is_configured() or not is_django_unittest(request):
            yield
            return

        # Fix/patch pytest.
        # Before pytest 5.4: https://github.com/pytest-dev/pytest/issues/5991
        # After pytest 5.4: https://github.com/pytest-dev/pytest-django/issues/824
        from _pytest.monkeypatch import MonkeyPatch

        def non_debugging_runtest(self):
            self._testcase(result=self)

        mp_debug = MonkeyPatch()
        mp_debug.setattr("_pytest.unittest.TestCaseFunction.runtest", non_debugging_runtest)

>       request.getfixturevalue("django_db_setup")

.tox/py38-djangomaster/lib/python3.8/site-packages/pytest_django/plugin.py:534:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

request = <SubRequest 'django_db_setup' for <TestCaseFunction test_ready>>, django_test_environment = None
django_db_blocker = <pytest_django.plugin._DatabaseBlocker object at 0x106a02a30>, 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=request.config.option.verbose,
                interactive=False,
                **setup_databases_args
            )
E           TypeError: setup_databases() missing 1 required keyword-only argument: 'time_keeper'

.tox/py38-djangomaster/lib/python3.8/site-packages/pytest_django/fixtures.py:105: TypeError

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions