| 1 |
@issue |
| 2 |
Feature: Issue #383 -- Handle (custom) Type parsing errors better |
| 3 |
|
| 4 |
. Custom type parsing errors that occur during step matching |
| 5 |
. lead currently to abortion of the test run. |
| 6 |
. In addition, the actual reason what occured is very low-level. |
| 7 |
. |
| 8 |
. DESIRED: |
| 9 |
. * Protect test runner/execution logic |
| 10 |
. * Improve handling of these kind of errors |
| 11 |
. * Provide better diagnostics |
| 12 |
. * Continue to run tests (if possible) |
| 13 |
. |
| 14 |
. NOTE: |
| 15 |
. This kind of problem is often caused by regular expressions that |
| 16 |
. are not specific enough for the type conversion (LAZY-REGEXP DESIGN). |
| 17 |
. Therefore, the problem occurs during type conversion/parsing phase |
| 18 |
. and not in the initial step detection/matching phase. |
| 19 |
. |
| 20 |
. RELATED: features/step_param.custom_types.feature |
| 21 |
|
| 22 |
|
| 23 |
Scenario: Type conversion fails |
| 24 |
Given a new working directory |
| 25 |
And a file named "features/steps/bad_type_converter_steps.py" with: |
| 26 |
""" |
| 27 |
from behave import step, register_type |
| 28 |
import parse |
| 29 |
|
| 30 |
@parse.with_pattern(r".*") # -- NOTE: Wildcard pattern, accepts anything. |
| 31 |
def parse_fails(text): |
| 32 |
raise ValueError(text) |
| 33 |
|
| 34 |
register_type(BadType=parse_fails) |
| 35 |
|
| 36 |
@step('a param with "BadType:{value:BadType}"') |
| 37 |
def step_param_with_badtype_value(context, value): |
| 38 |
assert False, "SHOULD_NEVER_COME_HERE: BadType converter raises error." |
| 39 |
""" |
| 40 |
And a file named "features/steps/reused_steps.py" with: |
| 41 |
""" |
| 42 |
from behave4cmd0 import passing_steps |
| 43 |
""" |
| 44 |
And a file named "behave.ini" with: |
| 45 |
""" |
| 46 |
[behave] |
| 47 |
show_timings = false |
| 48 |
""" |
| 49 |
And a file named "features/example.type_conversion_fails.feature" with: |
| 50 |
""" |
| 51 |
Feature: Type Conversion Fails |
| 52 |
Scenario: BadType raises ValueError during type conversion |
| 53 |
Given a param with "BadType:BAD_VALUE" |
| 54 |
|
| 55 |
Scenario: Ensure other scenarios are executed |
| 56 |
Then another step passes |
| 57 |
""" |
| 58 |
When I run "behave -f plain features/example.type_conversion_fails.feature" |
| 59 |
Then it should fail with: |
| 60 |
""" |
| 61 |
1 scenario passed, 1 failed, 0 skipped |
| 62 |
1 step passed, 1 failed, 0 skipped, 0 undefined |
| 63 |
""" |
| 64 |
And the command output should contain: |
| 65 |
""" |
| 66 |
Scenario: BadType raises ValueError during type conversion |
| 67 |
Given a param with "BadType:BAD_VALUE" ... failed |
| 68 |
Traceback (most recent call last): |
| 69 |
""" |
| 70 |
And the command output should contain: |
| 71 |
""" |
| 72 |
File "features/steps/bad_type_converter_steps.py", line 6, in parse_fails |
| 73 |
raise ValueError(text) |
| 74 |
""" |
| 75 |
And the command output should contain "ValueError: BAD_VALUE" |
| 76 |
And the command output should contain "StepParseError: BAD_VALUE" |