pytest-dev / pytest-dev/pytest-django
Please provide a session-scope 'settings' fixture
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.5k
- Forks
- 367
- PR merge metrics
- No merged PRs in 30d
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with SettingsWrapper and the existing settings fixture usage described in the issue; inspect how _to_restore is managed through finalization. Done means multiple SettingsWrapper instances keep independent restoration state, including the session-scoped use case, and the relevant fixture tests pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- django, python
- Domain
- testing
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100