Repository navigation
Snapshot context.fixtures in user mode to avoid ContextMaskWarning - #186
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The fixture-scope snapshot added in #179 ran in behave's default BEHAVE mode, which tagged
context.fixturesas behave-owned. Any later reassignment in a user hook (e.g.context.fixtures = []to suppress an inherited fixture) then tripped: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
Contexttracks an_origin[attr]mode for every attribute — set on the first assignment — and emitsContextMaskWarningwhen later assignments cross the mode boundary:ContextModeenum (BEHAVE / USER)Context.use_with_user_mode()— context manager that flips_modeto USERContext._emit_warning()— the source of the warning; fires when_mode is USERand_origin[attr] is not USERContext.__setattr__()— locks_origin[attr]on first assignmentOur monkey-patched
run_hooksnapshot runs before behave'swith 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-django52acceptance run —ContextMaskWarningno longer emitted; 12 features / 32 scenarios pass.tox -e py314-django60acceptance run — same result.tests/acceptance/environment.py:40).