| 1 |
@issue |
| 2 |
Feature: Issue #162 Unnecessary ContextMaskWarnings when assert fails or exception is raised |
| 3 |
|
| 4 |
. Behave shows unnecessary ContextMaskWarnings related to: |
| 5 |
. |
| 6 |
. * tags |
| 7 |
. * capture_stdout |
| 8 |
. * capture_stderr |
| 9 |
. * log_capture |
| 10 |
. |
| 11 |
. if: |
| 12 |
. |
| 13 |
. * an assertion fails in a step-definition/step-function |
| 14 |
. * an exception is raised by a step-definition/step-function |
| 15 |
. |
| 16 |
. and an additional scenario follows. |
| 17 |
. REASON: Context "behave" mode is not restored when an exception is raised. |
| 18 |
|
| 19 |
|
| 20 |
@setup |
| 21 |
Scenario: Feature Setup |
| 22 |
Given a new working directory |
| 23 |
And a file named "features/steps/steps.py" with: |
| 24 |
""" |
| 25 |
from behave import step |
| 26 |
|
| 27 |
@step('a step passes') |
| 28 |
def step_passes(context): |
| 29 |
pass |
| 30 |
|
| 31 |
@step('a step assert fails') |
| 32 |
def step_assert_fails(context): |
| 33 |
assert False, "XFAIL-STEP" |
| 34 |
|
| 35 |
@step('an exception is raised') |
| 36 |
def step_raises_exception(context): |
| 37 |
raise RuntimeError("XFAIL-STEP") |
| 38 |
""" |
| 39 |
|
| 40 |
|
| 41 |
Scenario: Assertion fails in a step |
| 42 |
Given a file named "features/example0162_assert_fails.feature" with: |
| 43 |
""" |
| 44 |
Feature: |
| 45 |
Scenario: |
| 46 |
Given a step passes |
| 47 |
When a step assert fails |
| 48 |
Then a step passes |
| 49 |
|
| 50 |
Scenario: |
| 51 |
Given a step passes |
| 52 |
""" |
| 53 |
When I run "behave -f plain features/example0162_assert_fails.feature" |
| 54 |
Then it should fail with: |
| 55 |
""" |
| 56 |
1 scenario passed, 1 failed, 0 skipped |
| 57 |
2 steps passed, 1 failed, 1 skipped, 0 undefined |
| 58 |
""" |
| 59 |
But the command output should not contain: |
| 60 |
""" |
| 61 |
ContextMaskWarning: user code is masking context attribute |
| 62 |
""" |
| 63 |
|
| 64 |
|
| 65 |
Scenario: Exception is raised in a step |
| 66 |
Given a file named "features/example0162_exception_raised.feature" with: |
| 67 |
""" |
| 68 |
Feature: |
| 69 |
Scenario: |
| 70 |
Given a step passes |
| 71 |
When an exception is raised |
| 72 |
Then a step passes |
| 73 |
|
| 74 |
Scenario: |
| 75 |
Given a step passes |
| 76 |
""" |
| 77 |
When I run "behave -f plain features/example0162_exception_raised.feature" |
| 78 |
Then it should fail with: |
| 79 |
""" |
| 80 |
1 scenario passed, 1 failed, 0 skipped |
| 81 |
2 steps passed, 1 failed, 1 skipped, 0 undefined |
| 82 |
""" |
| 83 |
But the command output should not contain: |
| 84 |
""" |
| 85 |
ContextMaskWarning: user code is masking context attribute |
| 86 |
""" |