Skip to content

Snapshot context.fixtures in user mode to avoid ContextMaskWarning - #186

Merged
bittner merged 1 commit into
mainfrom
fix/fixture-snapshot-user-mode
Jun 4, 2026
Merged

bittner merged 1 commit into
mainfrom
fix/fixture-snapshot-user-mode

Conversation

@bittner

@bittner bittner commented Jun 4, 2026

Copy link
Copy Markdown
Member

Summary

The fixture-scope snapshot added in #179 ran in behave's default BEHAVE mode, which tagged context.fixtures as behave-owned. Any later reassignment in a user hook (e.g. context.fixtures = [] to suppress an inherited fixture) then tripped:

ContextMaskWarning: user code is masking context attribute 'fixtures' originally set by behave

Fix: wrap the snapshot in context.use_with_user_mode() so behave records the attribute as user-owned. Subsequent reassignment by user code is then silent.

Background — BEHAVE vs USER mode

behave's Context tracks an _origin[attr] mode for every attribute — set on the first assignment — and emits ContextMaskWarning when later assignments cross the mode boundary:

Our monkey-patched run_hook snapshot runs before behave's with ctx.use_with_user_mode(): block around user hooks, so without an explicit user-mode wrapper, the first snapshot assignment recorded _origin['fixtures'] = BEHAVE.

Test plan

  • tox -e py314-django52 acceptance run — ContextMaskWarning no longer emitted; 12 features / 32 scenarios pass.
  • tox -e py314-django60 acceptance run — same result.
  • Confirmed the warning was coming from the "Override inherited fixtures with empty list" scenario (tests/acceptance/environment.py:40).

The fixture-scope snapshot added in #179 ran in behave's default BEHAVE
mode, which tagged ``context.fixtures`` as behave-owned.  Any later
reassignment in a user hook (``context.fixtures = [...]``) then tripped
``ContextMaskWarning: user code is masking context attribute 'fixtures'
originally set by behave``.

Wrap the snapshot in ``context.use_with_user_mode()`` so the attribute
is recorded as user-owned and reassignment by user code is silent.
@bittner bittner self-assigned this Jun 4, 2026
@bittner
bittner merged commit 2e8de5a into main Jun 4, 2026
13 checks passed
@bittner
bittner deleted the fix/fixture-snapshot-user-mode branch June 4, 2026 00:08
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

Successfully merging this pull request may close these issues.

1 participant