Skip to content

Multi db in fixture(scope='session') didn't work #934

Closed
@granescb

Description

@granescb

Look like if we will use scope session in fuxture that using multi db fixture will not work.
Example:

@pytest.fixture(scope='session')
@pytest.mark.django_db(databases=['default', 'other_db')
def create_unmanaged_db_models():
   #Make some db action
    ...

@pytest.mark.usefixtures('create_unmanaged_db_models')
@pytest.mark.django_db(databases=['default', settings.LEADGEN_DB])
def test_some_case():
    ...

Will raise follow exception
RuntimeError: Database access not allowed, use the "django_db" mark, or the "db" or "transactional_db" fixtures to enable it.

But if we will delete scope session code will work fine.
Example:

@pytest.fixture()
@pytest.mark.django_db(databases=['default', 'other_db')
def create_unmanaged_db_models():
   #Make some db action
    ...

@pytest.mark.usefixtures('create_unmanaged_db_models')
@pytest.mark.django_db(databases=['default', settings.LEADGEN_DB])
def test_some_case():
    ...

Package versions:
pytest-django==4.3.0
Django==3.2.3

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