-
Notifications
You must be signed in to change notification settings - Fork 53
Description
Currently, when a fixture is set for a scenario, it must be reset for all the other scenarios, as described in the documentation. This is not particularly user-friendly and leaves room for error.
The reason fixtures need manual resetting is that behave reuses the same context object across scenarios and features. Any attribute set on context (like context.fixtures) persists unless explicitly cleared.
To make this more user-friendly, we could automatically clear context.fixtures after setup_fixtures() processes it. This would mean:
- User sets
context.fixtures = ['foo.json']inbefore_scenario() - Our
setup_fixtures()reads and applies it tocontext.test.fixtures - We clear
context.fixturesso it doesn't carry over
This would require a one-line change in setup_fixtures() after line 79:
fixtures = getattr(context, 'fixtures', [])
if django.VERSION >= (5, 2):
context.test.__class__.fixtures = copy(fixtures)
else:
context.test.fixtures = copy(fixtures)
del context.fixtures # Auto-reset for next scenarioHowever, this could break existing code that:
- Appends to
context.fixturesinbefore_scenario()(like our test suite does) - Expects to read
context.fixturesafter it's been set
When this feature is added, we should issue a major release, because it will be a small but breaking change.