Skip to content

(Question) Running fixture / function before all tests #1069

@VaZark

Description

@VaZark

In our setup, we need to setup select postgres schemas for the app to work as expected. So I'd like to run a couple of commands after migrations are run.

The common recommendation everywhere is to use a session-scoped fixture with autouse=True. However, they are limited to the module. Is there a guaranteed way to run a function immediately after db migrations but before tests ?

I'd like to run the following function before tests. any pointers welcome :)

@pytest.fixture(scope="session", autouse=True)
def django_db_setup(django_db_setup, django_db_blocker):
    with django_db_blocker.unblock():
        tenant = Tenant(
            name="Test Environment",
            schema_name="testenv",
            tenant_key="TESTENV",
            frontend_url="http://localhost:3000",
            notification_email="tech@example.com",
        )
        tenant.save()

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