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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
|
@issue
@junit
Feature: Issue #446 -- Support scenario hook-errors with JUnitReporter
. Currently, when a hook error occurs in:
.
. * before_scenario()
. * after_scenario()
.
. a sanity check in the JUnitReporter prevents sane JUnit XML output.
@setup
Scenario: Skip scenario without steps
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/before_scenario_failure.feature" with:
"""
Feature: Alice
@hook_failure.before_scenario
Scenario: A1
Given a step passes
"""
And a file named "features/after_scenario_failure.feature" with:
"""
Feature: Bob
@hook_failure.after_scenario
Scenario: B1
Given another step passes
"""
And a file named "features/environment.py" with:
"""
def cause_hook_failure():
raise RuntimeError("OOPS")
def before_scenario(context, scenario):
if "hook_failure.before_scenario" in scenario.tags:
cause_hook_failure()
def after_scenario(context, scenario):
if "hook_failure.after_scenario" in scenario.tags:
cause_hook_failure()
"""
And a file named "behave.ini" with:
"""
[behave]
show_timings = false
[behave.userdata]
behave.reporter.junit.show_timestamp = False
behave.reporter.junit.show_hostname = False
"""
@not.with_python.version=3.8
Scenario: Hook error in before_scenario()
When I run "behave -f plain --junit features/before_scenario_failure.feature"
Then it should fail with:
"""
0 scenarios passed, 1 failed, 0 skipped
"""
And the command output should contain:
"""
HOOK-ERROR in before_scenario: RuntimeError: OOPS
"""
And the file "reports/TESTS-before_scenario_failure.xml" should contain:
"""
<testsuite errors="1" failures="0" name="before_scenario_failure.Alice" skipped="0" tests="1"
"""
And the file "reports/TESTS-before_scenario_failure.xml" should contain:
"""
<error message="HOOK-ERROR in before_scenario: RuntimeError: OOPS" type="RuntimeError">
"""
And the file "reports/TESTS-before_scenario_failure.xml" should contain:
"""
File "features/environment.py", line 6, in before_scenario
cause_hook_failure()
File "features/environment.py", line 2, in cause_hook_failure
raise RuntimeError("OOPS")
"""
And note that "the traceback is contained in the XML element <error/>"
@use.with_python.version=3.8
Scenario: Hook error in before_scenario()
When I run "behave -f plain --junit features/before_scenario_failure.feature"
Then it should fail with:
"""
0 scenarios passed, 1 failed, 0 skipped
"""
And the command output should contain:
"""
HOOK-ERROR in before_scenario: RuntimeError: OOPS
"""
And the file "reports/TESTS-before_scenario_failure.xml" should contain:
"""
<testsuite name="before_scenario_failure.Alice" tests="1" errors="1" failures="0" skipped="0"
"""
# -- HINT FOR: Python < 3.8
# <testsuite errors="1" failures="0" name="before_scenario_failure.Alice" skipped="0" tests="1"
And the file "reports/TESTS-before_scenario_failure.xml" should contain:
"""
<error type="RuntimeError" message="HOOK-ERROR in before_scenario: RuntimeError: OOPS">
"""
# -- HINT FOR: Python < 3.8
# <error message="HOOK-ERROR in before_scenario: RuntimeError: OOPS" type="RuntimeError">
And the file "reports/TESTS-before_scenario_failure.xml" should contain:
"""
File "features/environment.py", line 6, in before_scenario
cause_hook_failure()
File "features/environment.py", line 2, in cause_hook_failure
raise RuntimeError("OOPS")
"""
And note that "the traceback is contained in the XML element <error/>"
@not.with_python.version=3.8
Scenario: Hook error in after_scenario()
When I run "behave -f plain --junit features/after_scenario_failure.feature"
Then it should fail with:
"""
0 scenarios passed, 1 failed, 0 skipped
"""
And the command output should contain:
"""
Scenario: B1
Given another step passes ... passed
HOOK-ERROR in after_scenario: RuntimeError: OOPS
"""
And the file "reports/TESTS-after_scenario_failure.xml" should contain:
"""
<testsuite errors="1" failures="0" name="after_scenario_failure.Bob" skipped="0" tests="1"
"""
And the file "reports/TESTS-after_scenario_failure.xml" should contain:
"""
<error message="HOOK-ERROR in after_scenario: RuntimeError: OOPS" type="RuntimeError">
"""
And the file "reports/TESTS-after_scenario_failure.xml" should contain:
"""
File "features/environment.py", line 10, in after_scenario
cause_hook_failure()
File "features/environment.py", line 2, in cause_hook_failure
raise RuntimeError("OOPS")
"""
And note that "the traceback is contained in the XML element <error/>"
@use.with_python.version=3.8
Scenario: Hook error in after_scenario()
When I run "behave -f plain --junit features/after_scenario_failure.feature"
Then it should fail with:
"""
0 scenarios passed, 1 failed, 0 skipped
"""
And the command output should contain:
"""
Scenario: B1
Given another step passes ... passed
HOOK-ERROR in after_scenario: RuntimeError: OOPS
"""
And the file "reports/TESTS-after_scenario_failure.xml" should contain:
"""
<testsuite name="after_scenario_failure.Bob" tests="1" errors="1" failures="0" skipped="0"
"""
# -- HINT FOR: Python < 3.8
# <testsuite errors="1" failures="0" name="after_scenario_failure.Bob" skipped="0" tests="1"
And the file "reports/TESTS-after_scenario_failure.xml" should contain:
"""
<error type="RuntimeError" message="HOOK-ERROR in after_scenario: RuntimeError: OOPS">
"""
# -- HINT FOR: Python < 3.8
# <error message="HOOK-ERROR in after_scenario: RuntimeError: OOPS" type="RuntimeError">
And the file "reports/TESTS-after_scenario_failure.xml" should contain:
"""
File "features/environment.py", line 10, in after_scenario
cause_hook_failure()
File "features/environment.py", line 2, in cause_hook_failure
raise RuntimeError("OOPS")
"""
And note that "the traceback is contained in the XML element <error/>"
|