pytest-dev/pytest-django

Please provide a session-scope 'settings' fixture

Opened this issue · 0 comments

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.