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