Debian Codegraph @

issue.features/issue0446.feature

raw ◀ ▶
1 Debian patch touch this file
1 @issue
2 @junit
3 Feature: Issue #446 -- Support scenario hook-errors with JUnitReporter
4
5 . Currently, when a hook error occurs in:
6 .
7 . * before_scenario()
8 . * after_scenario()
9 .
10 . a sanity check in the JUnitReporter prevents sane JUnit XML output.
11
12
13 @setup
14 Scenario: Skip scenario without steps
15 Given a new working directory
16 And a file named "features/steps/pass_steps.py" with:
17 """
18 from behave import step
19
20 @step('{word:w} step passes')
21 def step_passes(context, word):
22 pass
23 """
24 And a file named "features/before_scenario_failure.feature" with:
25 """
26 Feature: Alice
27 @hook_failure.before_scenario
28 Scenario: A1
29 Given a step passes
30 """
31 And a file named "features/after_scenario_failure.feature" with:
32 """
33 Feature: Bob
34 @hook_failure.after_scenario
35 Scenario: B1
36 Given another step passes
37 """
38 And a file named "features/environment.py" with:
39 """
40 def cause_hook_failure():
41 raise RuntimeError("OOPS")
42
43 def before_scenario(context, scenario):
44 if "hook_failure.before_scenario" in scenario.tags:
45 cause_hook_failure()
46
47 def after_scenario(context, scenario):
48 if "hook_failure.after_scenario" in scenario.tags:
49 cause_hook_failure()
50 """
51 And a file named "behave.ini" with:
52 """
53 [behave]
54 show_timings = false
55
56 [behave.userdata]
57 behave.reporter.junit.show_timestamp = False
58 behave.reporter.junit.show_hostname = False
59 """
60
•61 @not.with_python.version=3.8
62 Scenario: Hook error in before_scenario()
63 When I run "behave -f plain --junit features/before_scenario_failure.feature"
64 Then it should fail with:
65 """
66 0 scenarios passed, 1 failed, 0 skipped
67 """
68 And the command output should contain:
69 """
70 HOOK-ERROR in before_scenario: RuntimeError: OOPS
71 """
72 And the file "reports/TESTS-before_scenario_failure.xml" should contain:
73 """
74 <testsuite errors="1" failures="0" name="before_scenario_failure.Alice" skipped="0" tests="1"
75 """
76 And the file "reports/TESTS-before_scenario_failure.xml" should contain:
77 """
78 <error message="HOOK-ERROR in before_scenario: RuntimeError: OOPS" type="RuntimeError">
79 """
80 And the file "reports/TESTS-before_scenario_failure.xml" should contain:
81 """
82 File "features/environment.py", line 6, in before_scenario
83 cause_hook_failure()
84 File "features/environment.py", line 2, in cause_hook_failure
85 raise RuntimeError("OOPS")
86 """
87 And note that "the traceback is contained in the XML element <error/>"
88
89
•90 @use.with_python.version=3.8
91 Scenario: Hook error in before_scenario()
92 When I run "behave -f plain --junit features/before_scenario_failure.feature"
93 Then it should fail with:
94 """
95 0 scenarios passed, 1 failed, 0 skipped
96 """
97 And the command output should contain:
98 """
99 HOOK-ERROR in before_scenario: RuntimeError: OOPS
100 """
101 And the file "reports/TESTS-before_scenario_failure.xml" should contain:
102 """
103 <testsuite name="before_scenario_failure.Alice" tests="1" errors="1" failures="0" skipped="0"
104 """
105 # -- HINT FOR: Python < 3.8
106 # <testsuite errors="1" failures="0" name="before_scenario_failure.Alice" skipped="0" tests="1"
107 And the file "reports/TESTS-before_scenario_failure.xml" should contain:
108 """
109 <error type="RuntimeError" message="HOOK-ERROR in before_scenario: RuntimeError: OOPS">
110 """
111 # -- HINT FOR: Python < 3.8
112 # <error message="HOOK-ERROR in before_scenario: RuntimeError: OOPS" type="RuntimeError">
113 And the file "reports/TESTS-before_scenario_failure.xml" should contain:
114 """
115 File "features/environment.py", line 6, in before_scenario
116 cause_hook_failure()
117 File "features/environment.py", line 2, in cause_hook_failure
118 raise RuntimeError("OOPS")
119 """
120 And note that "the traceback is contained in the XML element <error/>"
121
122
123 @not.with_python.version=3.8
124 Scenario: Hook error in after_scenario()
125 When I run "behave -f plain --junit features/after_scenario_failure.feature"
126 Then it should fail with:
127 """
128 0 scenarios passed, 1 failed, 0 skipped
129 """
130 And the command output should contain:
131 """
132 Scenario: B1
133 Given another step passes ... passed
134 HOOK-ERROR in after_scenario: RuntimeError: OOPS
135 """
136 And the file "reports/TESTS-after_scenario_failure.xml" should contain:
137 """
138 <testsuite errors="1" failures="0" name="after_scenario_failure.Bob" skipped="0" tests="1"
139 """
140 And the file "reports/TESTS-after_scenario_failure.xml" should contain:
141 """
142 <error message="HOOK-ERROR in after_scenario: RuntimeError: OOPS" type="RuntimeError">
143 """
144 And the file "reports/TESTS-after_scenario_failure.xml" should contain:
145 """
146 File "features/environment.py", line 10, in after_scenario
147 cause_hook_failure()
148 File "features/environment.py", line 2, in cause_hook_failure
149 raise RuntimeError("OOPS")
150 """
151 And note that "the traceback is contained in the XML element <error/>"
•152
153
154 @use.with_python.version=3.8
155 Scenario: Hook error in after_scenario()
156 When I run "behave -f plain --junit features/after_scenario_failure.feature"
157 Then it should fail with:
158 """
159 0 scenarios passed, 1 failed, 0 skipped
160 """
161 And the command output should contain:
162 """
163 Scenario: B1
164 Given another step passes ... passed
165 HOOK-ERROR in after_scenario: RuntimeError: OOPS
166 """
167 And the file "reports/TESTS-after_scenario_failure.xml" should contain:
168 """
169 <testsuite name="after_scenario_failure.Bob" tests="1" errors="1" failures="0" skipped="0"
170 """
171 # -- HINT FOR: Python < 3.8
172 # <testsuite errors="1" failures="0" name="after_scenario_failure.Bob" skipped="0" tests="1"
173 And the file "reports/TESTS-after_scenario_failure.xml" should contain:
174 """
175 <error type="RuntimeError" message="HOOK-ERROR in after_scenario: RuntimeError: OOPS">
176 """
177 # -- HINT FOR: Python < 3.8
178 # <error message="HOOK-ERROR in after_scenario: RuntimeError: OOPS" type="RuntimeError">
179 And the file "reports/TESTS-after_scenario_failure.xml" should contain:
180 """
181 File "features/environment.py", line 10, in after_scenario
182 cause_hook_failure()
183 File "features/environment.py", line 2, in cause_hook_failure
184 raise RuntimeError("OOPS")
185 """
186 And note that "the traceback is contained in the XML element <error/>"