Skip to content

Please provide a session-scope 'settings' fixture #1146

Description

@coredumperror

I wish it was as easy as this:

@pytest.fixture(scope="session")
def session_settings():
    """A Django settings object which restores changes after the test session"""
    skip_if_no_django()

    wrapper = SettingsWrapper()
    yield wrapper
    wrapper.finalize()

Unfortunately it's not, because SettingsWrapper._to_restore is a class attributes, rather than an instance attribute. So if you have any of the original settings fixture in your code, when those call finalize, they'll remove your session-scoped settings changes, too.

This should be an easy fix, tho: just make SettingsWrapper._to_restore an instance attribute, so that there can be multiple different SettingsWrappers in use at the same time, without interfering with each other.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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