Skip to content

Is it possible to "lock" context attributes? #1136

Closed Answered by jenisys
lu-maca asked this question in Q&A
Discussion options

You must be logged in to vote

behave does not protect user context variables. As you have stated, it raises only such a warning if you try to override/hide a behave context variable.

Currently, you will need to provide such a special ValueObject class, like a Constant object that protects itself against assignment (and raises a ContextMaskWarning if an assignment occurs).

NOTES:
Normally, you need a use_or_create_context_param(ctx, name, some_factory_func, *args, **kwargs) helper function that provides/stores a context variable is none exists.

EXAMPLE:

from behave import given, when, then, step
from behave4me.step_util import use_or_create_context_param

@step(„This step shall do something“)
def do_something(ctx):
    #…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@lu-maca
Comment options

@jenisys
Comment options

Answer selected by jenisys
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
2 participants