-
Hi all! I've tried to put an enumeration in a step definition to restrict the choices in the parameter values but I faced that I cannot set custom Exception for not valid values.
And I got the following output: @when(u'Choose from ChoicesEnum: dddd') But if I change the dict_parser method to raise en Exception than the code fails with an error because the library couldn't handle the exception.
behave\formatter\pretty.py", line 290, in print_step It is possible somehow to handle it or does it require code change? Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
All of the examples only match the known values and not the unknown ones (else/otherwise case). POSSIBLE SOLUTIONS (at runtime):
EXAMPLE FOR SOLUTION 1: @step("Choose from Choices: {param:Choices}")
def step_choices(ctx, param):
# -- CASE: Valid Choices values
pass
@step("Choose from Choices: {param}") # OR: {param:w} that only one word should be matched
def step_choices_otherwise(ctx, param):
# -- CASE: Invalid Choices values
# POSSIBLE REACTIONS: fail (HERE), ignore it, report problem, ...
assert false, "INVALID-CHOICES VALUE: %s" % param |
Beta Was this translation helpful? Give feedback.
-
Regarding the Exception in the HINT: |
Beta Was this translation helpful? Give feedback.
All of the examples only match the known values and not the unknown ones (else/otherwise case).
In your case, the problem was that feature file writer has used an "invalid step".
You can check for these kind of problems with:
behave --dry-run
(detects undefined steps without paying the runtime costs)POSSIBLE SOLUTIONS (at runtime):
EXAMPLE FOR SOLUTION 1: