Skip to content

Automatically reset context.features #179

@bittner

Description

@bittner

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:

  1. User sets context.fixtures = ['foo.json'] in before_scenario()
  2. Our setup_fixtures() reads and applies it to context.test.fixtures
  3. We clear context.fixtures so 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 scenario

However, this could break existing code that:

  • Appends to context.fixtures in before_scenario() (like our test suite does)
  • Expects to read context.fixtures after it's been set

When this feature is added, we should issue a major release, because it will be a small but breaking change.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions