Skip to content

django.test.TestCase with multiples database doesn't create secondary db in 4.11.0 #1188

@m-lamour

Description

@m-lamour

With the 4.11.0 version, if a Django TestCase is setup to use multiples database with the databases attribute, only the default database is created on runtime.

class Test(TestCase):
    databases = {"default", "db2"}

Trying to add the decorator @pytest.mark.django_db(databases=['default', 'db2']) on the class doesn't work either.

The problem seems to come from the line 133 in pytest_django/fixtures.py

The line tries to get an attribute from the test function and not from the test class.

        databases = getattr(test_cls, "databases", None)

This fixes the problem with Django TestCase without altering pytest.mark.django_db

PS : the line 132 (serialized_rollback) seems to be broken also. I have not tried using serialized_rollback, so I can't confirm.

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