Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
coredumperror opened this issue Sep 19, 2024 · 0 comments
Open

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

coredumperror opened this issue Sep 19, 2024 · 0 comments

Comments

@coredumperror
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant