Skip to content

Multiple django.setup() calls break other plugins #531

@pakal

Description

@pakal

In pytest-django hooks, _setup_django() is called multiple times, in conftest setup and as a a trylast, and it leads to multiple resets of logging config (driven by django LOGGING setting).

Inbetween these calls, other plugins like pytest-capturelog try to setup their own logging handlers, but these get reset. I've monkey patched like below, but I guess _setup_django() could use a flag to prevent its multiple execution.

def pytest_configure():
    # we have to prevent bug where pytest calls django.setup() multiple
    # times, breaking the logging conf (and pytest-capturelog plugin)
    import django.apps
    if django.apps.apps.ready:
        django.setup = lambda: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions