| 1 |
@issue |
| 2 |
@user_error |
| 3 |
@python2.problem |
| 4 |
Feature: Issue #506 -- Behave stops on error |
| 5 |
|
| 6 |
. ANALYSIS: |
| 7 |
. Using exception.__cause__ = original_exception causes problems in Python2 |
| 8 |
. When you use the Python3 chained-exception mechanism, |
| 9 |
. you should better ensure that the "original_exception.__traceback__" attribute |
| 10 |
. exists. Otherwise, a new exception (missing attribute) is raised |
| 11 |
. when you format the traceback, |
| 12 |
|
| 13 |
Scenario: |
| 14 |
Given a new working directory |
| 15 |
And a file named "features/steps/pass_steps.py" with: |
| 16 |
""" |
| 17 |
from behave import step |
| 18 |
|
| 19 |
@step('{word:w} step passes') |
| 20 |
def step_passes(context, word): |
| 21 |
pass |
| 22 |
|
| 23 |
""" |
| 24 |
And a file named "features/steps/steps.py" with: |
| 25 |
""" |
| 26 |
from behave import when, then |
| 27 |
from behave._types import ChainedExceptionUtil |
| 28 |
import copy |
| 29 |
|
| 30 |
@when('I bad chained-exception causes my step to fail') |
| 31 |
def step_bad_usage_of_chained_exception(context): |
| 32 |
# -- BAD IMPLEMENATION: |
| 33 |
exception = ZeroDivisionError('integer division or modulo by zero') |
| 34 |
exception.__cause__ = copy.copy(exception) |
| 35 |
raise exception |
| 36 |
|
| 37 |
@when('a chained-exception causes my step to fail') |
| 38 |
def step_chained_exception_causes_failure(context): |
| 39 |
try: |
| 40 |
raise ZeroDivisionError("OOPS-1") |
| 41 |
except ZeroDivisionError as e: |
| 42 |
e2 = RuntimeError("OOPS-2") |
| 43 |
ChainedExceptionUtil.set_cause(e2, e) |
| 44 |
raise e2 |
| 45 |
|
| 46 |
@then('this step must be executed') |
| 47 |
def step_check_step(context): |
| 48 |
pass |
| 49 |
""" |
| 50 |
And a file named "features/syndrome.feature" with: |
| 51 |
""" |
| 52 |
Feature: Failing step which can lead to stop behave |
| 53 |
|
| 54 |
@failing |
| 55 |
Scenario: Run stopping behave scenario |
| 56 |
When a chained-exception causes my step to fail |
| 57 |
Then this step must be executed |
| 58 |
""" |
| 59 |
When I run "behave -f plain features/syndrome.feature" |
| 60 |
Then it should fail with: |
| 61 |
""" |
| 62 |
0 scenarios passed, 1 failed, 0 skipped |
| 63 |
""" |
| 64 |
And the command output should contain: |
| 65 |
""" |
| 66 |
ZeroDivisionError: OOPS-1 |
| 67 |
|
| 68 |
The above exception was the direct cause of the following exception: |
| 69 |
|
| 70 |
Traceback (most recent call last): |
| 71 |
""" |
| 72 |
And the command output should contain: |
| 73 |
""" |
| 74 |
File "features/steps/steps.py", line 19, in step_chained_exception_causes_failure |
| 75 |
raise e2 |
| 76 |
RuntimeError: OOPS-2 |
| 77 |
""" |