| 1 |
@issue |
| 2 |
Feature: Issue #96: Sub-steps failed without any error info to help debug issue |
| 3 |
|
| 4 |
. I am trying to run execute_steps. One of them fails, but the error output |
| 5 |
. from behave has no details whatsoever. It is virtually impossible |
| 6 |
. to figure out why it failed. as no error output is present except the |
| 7 |
. final error message |
| 8 |
. |
| 9 |
. def before_scenario(context,scenario): |
| 10 |
. context.execute_steps(u''' |
| 11 |
. When "admin:admin" sends POST "/tasks/testStart" |
| 12 |
. Then I expect HTTP code 200 |
| 13 |
. ''') |
| 14 |
. |
| 15 |
. File ".../behave/runner.py", line 262, in execute_steps |
| 16 |
. assert False, "FAILED SUB-STEP: %s" % step |
| 17 |
. AssertionError: FAILED SUB-STEP: When "admin:admin" sends POST "/tasks/testStart" |
| 18 |
. |
| 19 |
. All we get is the "sub-step failed" but no info whatsoever |
| 20 |
. as to why it failed... |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
Background: |
| 25 |
Given a new working directory |
| 26 |
And a file named "features/steps/steps.py" with: |
| 27 |
""" |
| 28 |
from behave import step |
| 29 |
import sys |
| 30 |
|
| 31 |
@step(u'a step passes') |
| 32 |
def step_passes(context): |
| 33 |
pass |
| 34 |
|
| 35 |
@step(u'a step fails') |
| 36 |
def step_fails(context): |
| 37 |
assert False, 'EXPECT: Step fails.' |
| 38 |
|
| 39 |
@step(u'a step fails with stdout "{message}"') |
| 40 |
def step_fails_with_stdout(context, message): |
| 41 |
sys.stdout.write("%s\n" % message) |
| 42 |
assert False, 'EXPECT: Step fails with stdout.' |
| 43 |
|
| 44 |
@step(u'a step fails with stderr "{message}"') |
| 45 |
def step_fails_with_stderr(context, message): |
| 46 |
sys.stderr.write("%s\n" % message) |
| 47 |
assert False, 'EXPECT: Step fails with stderr.' |
| 48 |
|
| 49 |
@step(u'a step raises an error "{message}"') |
| 50 |
def step_raises_exception(context, message): |
| 51 |
raise RuntimeError(message) |
| 52 |
|
| 53 |
@step(u'the following steps should pass') |
| 54 |
def step_following_steps_should_pass(context): |
| 55 |
context.execute_steps(context.text.strip()) |
| 56 |
""" |
| 57 |
|
| 58 |
Scenario: Execute steps and one fails (EXPECTATION-MISMATCH: Assert fails) |
| 59 |
Given a file named "features/issue96_case1.feature" with: |
| 60 |
''' |
| 61 |
Feature: |
| 62 |
Scenario: |
| 63 |
When the following steps should pass: |
| 64 |
""" |
| 65 |
Given a step passes |
| 66 |
When a step fails |
| 67 |
Then a step passes |
| 68 |
""" |
| 69 |
''' |
| 70 |
When I run "behave -c features/issue96_case1.feature" |
| 71 |
Then it should fail with: |
| 72 |
""" |
| 73 |
Assertion Failed: FAILED SUB-STEP: When a step fails |
| 74 |
Substep info: Assertion Failed: EXPECT: Step fails. |
| 75 |
""" |
| 76 |
|
| 77 |
Scenario: Execute steps and error occurs (UNEXPECTED: exception is raised) |
| 78 |
Given a file named "features/issue96_case2.feature" with: |
| 79 |
''' |
| 80 |
Feature: |
| 81 |
Scenario: |
| 82 |
When the following steps should pass: |
| 83 |
""" |
| 84 |
Given a step passes |
| 85 |
When a step raises an error "Alice is alive" |
| 86 |
Then a step passes |
| 87 |
""" |
| 88 |
''' |
| 89 |
When I run "behave -c features/issue96_case2.feature" |
| 90 |
Then it should fail with: |
| 91 |
""" |
| 92 |
RuntimeError: Alice is alive |
| 93 |
""" |
| 94 |
And the command output should contain: |
| 95 |
""" |
| 96 |
Assertion Failed: FAILED SUB-STEP: When a step raises an error "Alice is alive" |
| 97 |
Substep info: Traceback (most recent call last): |
| 98 |
""" |
| 99 |
|
| 100 |
Scenario: Execute steps and one fails with stdout capture |
| 101 |
Given a file named "features/issue96_case3.feature" with: |
| 102 |
''' |
| 103 |
Feature: |
| 104 |
Scenario: |
| 105 |
When the following steps should pass: |
| 106 |
""" |
| 107 |
Given a step passes |
| 108 |
When a step fails with stdout "STDOUT: Alice is alive" |
| 109 |
Then a step passes |
| 110 |
""" |
| 111 |
''' |
| 112 |
When I run "behave -c features/issue96_case3.feature" |
| 113 |
Then it should fail with: |
| 114 |
""" |
| 115 |
Assertion Failed: FAILED SUB-STEP: When a step fails with stdout "STDOUT: Alice is alive" |
| 116 |
Substep info: Assertion Failed: EXPECT: Step fails with stdout. |
| 117 |
""" |
| 118 |
And the command output should contain: |
| 119 |
""" |
| 120 |
Captured stdout: |
| 121 |
STDOUT: Alice is alive |
| 122 |
""" |
| 123 |
|
| 124 |
|
| 125 |
Scenario: Execute steps and one fails with stderr capture |
| 126 |
Given a file named "features/issue96_case4.feature" with: |
| 127 |
''' |
| 128 |
Feature: |
| 129 |
Scenario: |
| 130 |
When the following steps should pass: |
| 131 |
""" |
| 132 |
Given a step passes |
| 133 |
When a step fails with stderr "STDERR: Alice is alive" |
| 134 |
Then a step passes |
| 135 |
""" |
| 136 |
''' |
| 137 |
When I run "behave -c features/issue96_case4.feature" |
| 138 |
Then it should fail with: |
| 139 |
""" |
| 140 |
Assertion Failed: FAILED SUB-STEP: When a step fails with stderr "STDERR: Alice is alive" |
| 141 |
Substep info: Assertion Failed: EXPECT: Step fails with stderr. |
| 142 |
""" |
| 143 |
And the command output should contain: |
| 144 |
""" |
| 145 |
Captured stderr: |
| 146 |
STDERR: Alice is alive |
| 147 |
""" |
| 148 |
|
| 149 |
Scenario: Execute steps and fail in before_scenario hook |
| 150 |
Given a file named "features/issue96_case5.feature" with: |
| 151 |
""" |
| 152 |
Feature: |
| 153 |
Scenario: |
| 154 |
Given a step passes |
| 155 |
When a step passes |
| 156 |
Then a step passes |
| 157 |
""" |
| 158 |
And a file named "features/environment.py" with: |
| 159 |
""" |
| 160 |
def before_scenario(context, scenario): |
| 161 |
context.execute_steps(u''' |
| 162 |
Given a step passes |
| 163 |
When a step passes |
| 164 |
Then a step fails |
| 165 |
''') |
| 166 |
""" |
| 167 |
When I run "behave -c features/issue96_case5.feature" |
| 168 |
Then it should fail with: |
| 169 |
""" |
| 170 |
HOOK-ERROR in before_scenario: AssertionError: FAILED SUB-STEP: Then a step fails |
| 171 |
Substep info: Assertion Failed: EXPECT: Step fails. |
| 172 |
""" |
| 173 |
|