Commit | Line | Data |
---|---|---|
a8cb1e72 CB |
1 | Fix build with Python 3.8, this is a patch based on upstream commit [1]. |
2 | ||
3 | 1: c000c88eb5239b87f299c85e83b349b0ef387ae7 | |
4 | ||
5 | ||
6 | diff --git a/behave.ini b/behave.ini | |
7 | index 45c0f0d7..952240d6 100644 | |
8 | --- a/behave.ini | |
9 | +++ b/behave.ini | |
10 | @@ -15,8 +15,9 @@ show_skipped = false | |
11 | format = rerun | |
12 | progress3 | |
13 | outfiles = rerun.txt | |
14 | - reports/report_progress3.txt | |
15 | + build/behave.reports/report_progress3.txt | |
16 | junit = true | |
17 | +junit_directory = build/behave.reports | |
18 | logging_level = INFO | |
19 | # logging_format = LOG.%(levelname)-8s %(name)-10s: %(message)s | |
20 | # logging_format = LOG.%(levelname)-8s %(asctime)s %(name)-10s: %(message)s | |
21 | diff --git a/features/environment.py b/features/environment.py | |
22 | index 4744e89a..3769ee40 100644 | |
23 | --- a/features/environment.py | |
24 | +++ b/features/environment.py | |
25 | @@ -1,5 +1,7 @@ | |
26 | # -*- coding: UTF-8 -*- | |
27 | +# FILE: features/environemnt.py | |
28 | ||
29 | +from __future__ import absolute_import, print_function | |
30 | from behave.tag_matcher import ActiveTagMatcher, setup_active_tag_values | |
31 | from behave4cmd0.setup_command_shell import setup_command_shell_processors4behave | |
32 | import platform | |
33 | @@ -20,6 +22,15 @@ | |
34 | } | |
35 | active_tag_matcher = ActiveTagMatcher(active_tag_value_provider) | |
36 | ||
37 | + | |
38 | +def print_active_tags_summary(): | |
39 | + active_tag_data = active_tag_value_provider | |
40 | + print("ACTIVE-TAG SUMMARY:") | |
41 | + print("use.with_python.version=%s" % active_tag_data.get("python.version")) | |
42 | + # print("use.with_os=%s" % active_tag_data.get("os")) | |
43 | + print() | |
44 | + | |
45 | + | |
46 | # ----------------------------------------------------------------------------- | |
47 | # HOOKS: | |
48 | # ----------------------------------------------------------------------------- | |
49 | @@ -30,11 +41,14 @@ def before_all(context): | |
50 | setup_python_path() | |
51 | setup_context_with_global_params_test(context) | |
52 | setup_command_shell_processors4behave() | |
53 | + print_active_tags_summary() | |
54 | + | |
55 | ||
56 | def before_feature(context, feature): | |
57 | if active_tag_matcher.should_exclude_with(feature.tags): | |
58 | feature.skip(reason=active_tag_matcher.exclude_reason) | |
59 | ||
60 | + | |
61 | def before_scenario(context, scenario): | |
62 | if active_tag_matcher.should_exclude_with(scenario.effective_tags): | |
63 | scenario.skip(reason=active_tag_matcher.exclude_reason) | |
64 | diff --git a/features/step.duplicated_step.feature b/features/step.duplicated_step.feature | |
65 | index 59888b0f..396cca27 100644 | |
66 | --- a/features/step.duplicated_step.feature | |
67 | +++ b/features/step.duplicated_step.feature | |
68 | @@ -32,11 +32,11 @@ Feature: Duplicated Step Definitions | |
69 | AmbiguousStep: @given('I call Alice') has already been defined in | |
70 | existing step @given('I call Alice') at features/steps/alice_steps.py:3 | |
71 | """ | |
72 | - And the command output should contain: | |
73 | - """ | |
74 | - File "features/steps/alice_steps.py", line 7, in <module> | |
75 | - @given(u'I call Alice') | |
76 | - """ | |
77 | + # -- DISABLED: Python 3.8 traceback line numbers differ w/ decorators (+1). | |
78 | + # And the command output should contain: | |
79 | + # """ | |
80 | + # File "features/steps/alice_steps.py", line 7, in <module> | |
81 | + # """ | |
82 | ||
83 | ||
84 | Scenario: Duplicated Step Definition in another File | |
85 | @@ -70,11 +70,11 @@ Feature: Duplicated Step Definitions | |
86 | AmbiguousStep: @given('I call Bob') has already been defined in | |
87 | existing step @given('I call Bob') at features/steps/bob1_steps.py:3 | |
88 | """ | |
89 | - And the command output should contain: | |
90 | - """ | |
91 | - File "features/steps/bob2_steps.py", line 3, in <module> | |
92 | - @given('I call Bob') | |
93 | - """ | |
94 | + # -- DISABLED: Python 3.8 traceback line numbers differ w/ decorators (+1). | |
95 | + # And the command output should contain: | |
96 | + # """ | |
97 | + # File "features/steps/bob2_steps.py", line 3, in <module> | |
98 | + # """ | |
99 | ||
100 | @xfail | |
101 | Scenario: Duplicated Same Step Definition via import from another File | |
102 | diff --git a/issue.features/environment.py b/issue.features/environment.py | |
103 | index 2dfec751..7e48ee03 100644 | |
104 | --- a/issue.features/environment.py | |
105 | +++ b/issue.features/environment.py | |
106 | @@ -1,5 +1,5 @@ | |
107 | # -*- coding: UTF-8 -*- | |
108 | -# FILE: features/environment.py | |
109 | +# FILE: issue.features/environemnt.py | |
110 | # pylint: disable=unused-argument | |
111 | """ | |
112 | Functionality: | |
113 | @@ -7,17 +7,20 @@ | |
114 | * active tags | |
115 | """ | |
116 | ||
117 | -from __future__ import print_function | |
118 | + | |
119 | +from __future__ import absolute_import, print_function | |
120 | import sys | |
121 | import platform | |
122 | import os.path | |
123 | import six | |
124 | from behave.tag_matcher import ActiveTagMatcher | |
125 | from behave4cmd0.setup_command_shell import setup_command_shell_processors4behave | |
126 | -# PREPARED: | |
127 | -# from behave.tag_matcher import setup_active_tag_values | |
128 | +# PREPARED: from behave.tag_matcher import setup_active_tag_values | |
129 | ||
130 | ||
131 | +# --------------------------------------------------------------------------- | |
132 | +# TEST SUPPORT: For Active Tags | |
133 | +# --------------------------------------------------------------------------- | |
134 | def require_tool(tool_name): | |
135 | """Check if a tool (an executable program) is provided on this platform. | |
136 | ||
137 | @@ -45,12 +48,14 @@ def require_tool(tool_name): | |
138 | # print("TOOL-NOT-FOUND: %s" % tool_name) | |
139 | return False | |
140 | ||
141 | + | |
142 | def as_bool_string(value): | |
143 | if bool(value): | |
144 | return "yes" | |
145 | else: | |
146 | return "no" | |
147 | ||
148 | + | |
149 | def discover_ci_server(): | |
150 | # pylint: disable=invalid-name | |
151 | ci_server = "none" | |
152 | @@ -67,11 +72,17 @@ def discover_ci_server(): | |
153 | return ci_server | |
154 | ||
155 | ||
156 | +# --------------------------------------------------------------------------- | |
157 | +# BEHAVE SUPPORT: Active Tags | |
158 | +# --------------------------------------------------------------------------- | |
159 | # -- MATCHES ANY TAGS: @use.with_{category}={value} | |
160 | # NOTE: active_tag_value_provider provides category values for active tags. | |
161 | +python_version = "%s.%s" % sys.version_info[:2] | |
162 | active_tag_value_provider = { | |
163 | + "platform": sys.platform, | |
164 | "python2": str(six.PY2).lower(), | |
165 | "python3": str(six.PY3).lower(), | |
166 | + "python.version": python_version, | |
167 | # -- python.implementation: cpython, pypy, jython, ironpython | |
168 | "python.implementation": platform.python_implementation().lower(), | |
169 | "pypy": str("__pypy__" in sys.modules).lower(), | |
170 | @@ -82,17 +92,33 @@ def discover_ci_server(): | |
171 | } | |
172 | active_tag_matcher = ActiveTagMatcher(active_tag_value_provider) | |
173 | ||
174 | + | |
175 | +def print_active_tags_summary(): | |
176 | + active_tag_data = active_tag_value_provider | |
177 | + print("ACTIVE-TAG SUMMARY:") | |
178 | + print("use.with_python.version=%s" % active_tag_data.get("python.version")) | |
179 | + # print("use.with_platform=%s" % active_tag_data.get("platform")) | |
180 | + # print("use.with_os=%s" % active_tag_data.get("os")) | |
181 | + print() | |
182 | + | |
183 | + | |
184 | +# --------------------------------------------------------------------------- | |
185 | +# BEHAVE HOOKS: | |
186 | +# --------------------------------------------------------------------------- | |
187 | def before_all(context): | |
188 | # -- SETUP ACTIVE-TAG MATCHER (with userdata): | |
189 | # USE: behave -D browser=safari ... | |
190 | - # NOT-NEEDED: setup_active_tag_values(active_tag_value_provider, | |
191 | - # context.config.userdata) | |
192 | + # NOT-NEEDED: | |
193 | + # setup_active_tag_values(active_tag_value_provider, context.config.userdata) | |
194 | setup_command_shell_processors4behave() | |
195 | + print_active_tags_summary() | |
196 | + | |
197 | ||
198 | def before_feature(context, feature): | |
199 | if active_tag_matcher.should_exclude_with(feature.tags): | |
200 | feature.skip(reason=active_tag_matcher.exclude_reason) | |
201 | ||
202 | + | |
203 | def before_scenario(context, scenario): | |
204 | if active_tag_matcher.should_exclude_with(scenario.effective_tags): | |
205 | scenario.skip(reason=active_tag_matcher.exclude_reason) | |
206 | diff --git a/issue.features/issue0330.feature b/issue.features/issue0330.feature | |
207 | index dc1ebe75..81cb6e29 100644 | |
208 | --- a/issue.features/issue0330.feature | |
209 | +++ b/issue.features/issue0330.feature | |
210 | @@ -70,6 +70,7 @@ Feature: Issue #330: Skipped scenarios are included in junit reports when --no-s | |
211 | And note that "bob.feature is skipped" | |
212 | ||
213 | ||
214 | + @not.with_python.version=3.8 | |
215 | Scenario: Junit report for skipped feature is created with --show-skipped | |
216 | When I run "behave --junit -t @tag1 --show-skipped @alice_and_bob.featureset" | |
217 | Then it should pass with: | |
218 | @@ -83,6 +84,23 @@ Feature: Issue #330: Skipped scenarios are included in junit reports when --no-s | |
219 | <testsuite errors="0" failures="0" name="bob.Bob" skipped="1" tests="1" time="0.0"> | |
220 | """ | |
221 | ||
222 | + @use.with_python.version=3.8 | |
223 | + Scenario: Junit report for skipped feature is created with --show-skipped | |
224 | + When I run "behave --junit -t @tag1 --show-skipped @alice_and_bob.featureset" | |
225 | + Then it should pass with: | |
226 | + """ | |
227 | + 1 feature passed, 0 failed, 1 skipped | |
228 | + """ | |
229 | + And a file named "test_results/TESTS-alice.xml" exists | |
230 | + And a file named "test_results/TESTS-bob.xml" exists | |
231 | + And the file "test_results/TESTS-bob.xml" should contain: | |
232 | + """ | |
233 | + <testsuite name="bob.Bob" tests="1" errors="0" failures="0" skipped="1" time="0.0"> | |
234 | + """ | |
235 | + # -- HINT FOR: Python < 3.8 | |
236 | + # <testsuite errors="0" failures="0" name="bob.Bob" skipped="1" tests="1" time="0.0"> | |
237 | + | |
238 | + @not.with_python.version=3.8 | |
239 | Scenario: Junit report for skipped scenario is neither shown nor counted with --no-skipped | |
240 | When I run "behave --junit -t @tag1 --no-skipped" | |
241 | Then it should pass with: | |
242 | @@ -102,7 +120,30 @@ Feature: Issue #330: Skipped scenarios are included in junit reports when --no-s | |
243 | """ | |
244 | And note that "Charly2 is the skipped scenarion in charly.feature" | |
245 | ||
246 | + @use.with_python.version=3.8 | |
247 | + Scenario: Junit report for skipped scenario is neither shown nor counted with --no-skipped | |
248 | + When I run "behave --junit -t @tag1 --no-skipped" | |
249 | + Then it should pass with: | |
250 | + """ | |
251 | + 2 features passed, 0 failed, 1 skipped | |
252 | + 2 scenarios passed, 0 failed, 2 skipped | |
253 | + """ | |
254 | + And a file named "test_results/TESTS-alice.xml" exists | |
255 | + And a file named "test_results/TESTS-charly.xml" exists | |
256 | + And the file "test_results/TESTS-charly.xml" should contain: | |
257 | + """ | |
258 | + <testsuite name="charly.Charly" tests="1" errors="0" failures="0" skipped="0" | |
259 | + """ | |
260 | + # -- HINT FOR: Python < 3.8 | |
261 | + # <testsuite errors="0" failures="0" name="charly.Charly" skipped="0" tests="1" | |
262 | + And the file "test_results/TESTS-charly.xml" should not contain: | |
263 | + """ | |
264 | + <testcase classname="charly.Charly" name="Charly2" | |
265 | + """ | |
266 | + And note that "Charly2 is the skipped scenarion in charly.feature" | |
267 | + | |
268 | ||
269 | + @not.with_python.version=3.8 | |
270 | Scenario: Junit report for skipped scenario is shown and counted with --show-skipped | |
271 | When I run "behave --junit -t @tag1 --show-skipped" | |
272 | Then it should pass with: | |
273 | @@ -122,3 +163,26 @@ Feature: Issue #330: Skipped scenarios are included in junit reports when --no-s | |
274 | """ | |
275 | And note that "Charly2 is the skipped scenarion in charly.feature" | |
276 | ||
277 | + | |
278 | + @use.with_python.version=3.8 | |
279 | + Scenario: Junit report for skipped scenario is shown and counted with --show-skipped | |
280 | + When I run "behave --junit -t @tag1 --show-skipped" | |
281 | + Then it should pass with: | |
282 | + """ | |
283 | + 2 features passed, 0 failed, 1 skipped | |
284 | + 2 scenarios passed, 0 failed, 2 skipped | |
285 | + """ | |
286 | + And a file named "test_results/TESTS-alice.xml" exists | |
287 | + And a file named "test_results/TESTS-charly.xml" exists | |
288 | + And the file "test_results/TESTS-charly.xml" should contain: | |
289 | + """ | |
290 | + <testsuite name="charly.Charly" tests="2" errors="0" failures="0" skipped="1" | |
291 | + """ | |
292 | + # HINT: Python < 3.8 | |
293 | + # <testsuite errors="0" failures="0" name="charly.Charly" skipped="1" tests="2" | |
294 | + And the file "test_results/TESTS-charly.xml" should contain: | |
295 | + """ | |
296 | + <testcase classname="charly.Charly" name="Charly2" status="skipped" | |
297 | + """ | |
298 | + And note that "Charly2 is the skipped scenarion in charly.feature" | |
299 | + | |
300 | diff --git a/issue.features/issue0446.feature b/issue.features/issue0446.feature | |
301 | index a2ed892d..901bdec5 100644 | |
302 | --- a/issue.features/issue0446.feature | |
303 | +++ b/issue.features/issue0446.feature | |
304 | @@ -58,6 +58,7 @@ Feature: Issue #446 -- Support scenario hook-errors with JUnitReporter | |
305 | behave.reporter.junit.show_hostname = False | |
306 | """ | |
307 | ||
308 | + @not.with_python.version=3.8 | |
309 | Scenario: Hook error in before_scenario() | |
310 | When I run "behave -f plain --junit features/before_scenario_failure.feature" | |
311 | Then it should fail with: | |
312 | @@ -86,6 +87,40 @@ Feature: Issue #446 -- Support scenario hook-errors with JUnitReporter | |
313 | And note that "the traceback is contained in the XML element <error/>" | |
314 | ||
315 | ||
316 | + @use.with_python.version=3.8 | |
317 | + Scenario: Hook error in before_scenario() | |
318 | + When I run "behave -f plain --junit features/before_scenario_failure.feature" | |
319 | + Then it should fail with: | |
320 | + """ | |
321 | + 0 scenarios passed, 1 failed, 0 skipped | |
322 | + """ | |
323 | + And the command output should contain: | |
324 | + """ | |
325 | + HOOK-ERROR in before_scenario: RuntimeError: OOPS | |
326 | + """ | |
327 | + And the file "reports/TESTS-before_scenario_failure.xml" should contain: | |
328 | + """ | |
329 | + <testsuite name="before_scenario_failure.Alice" tests="1" errors="1" failures="0" skipped="0" | |
330 | + """ | |
331 | + # -- HINT FOR: Python < 3.8 | |
332 | + # <testsuite errors="1" failures="0" name="before_scenario_failure.Alice" skipped="0" tests="1" | |
333 | + And the file "reports/TESTS-before_scenario_failure.xml" should contain: | |
334 | + """ | |
335 | + <error type="RuntimeError" message="HOOK-ERROR in before_scenario: RuntimeError: OOPS"> | |
336 | + """ | |
337 | + # -- HINT FOR: Python < 3.8 | |
338 | + # <error message="HOOK-ERROR in before_scenario: RuntimeError: OOPS" type="RuntimeError"> | |
339 | + And the file "reports/TESTS-before_scenario_failure.xml" should contain: | |
340 | + """ | |
341 | + File "features/environment.py", line 6, in before_scenario | |
342 | + cause_hook_failure() | |
343 | + File "features/environment.py", line 2, in cause_hook_failure | |
344 | + raise RuntimeError("OOPS") | |
345 | + """ | |
346 | + And note that "the traceback is contained in the XML element <error/>" | |
347 | + | |
348 | + | |
349 | + @not.with_python.version=3.8 | |
350 | Scenario: Hook error in after_scenario() | |
351 | When I run "behave -f plain --junit features/after_scenario_failure.feature" | |
352 | Then it should fail with: | |
353 | @@ -114,3 +149,38 @@ Feature: Issue #446 -- Support scenario hook-errors with JUnitReporter | |
354 | raise RuntimeError("OOPS") | |
355 | """ | |
356 | And note that "the traceback is contained in the XML element <error/>" | |
357 | + | |
358 | + | |
359 | + @use.with_python.version=3.8 | |
360 | + Scenario: Hook error in after_scenario() | |
361 | + When I run "behave -f plain --junit features/after_scenario_failure.feature" | |
362 | + Then it should fail with: | |
363 | + """ | |
364 | + 0 scenarios passed, 1 failed, 0 skipped | |
365 | + """ | |
366 | + And the command output should contain: | |
367 | + """ | |
368 | + Scenario: B1 | |
369 | + Given another step passes ... passed | |
370 | + HOOK-ERROR in after_scenario: RuntimeError: OOPS | |
371 | + """ | |
372 | + And the file "reports/TESTS-after_scenario_failure.xml" should contain: | |
373 | + """ | |
374 | + <testsuite name="after_scenario_failure.Bob" tests="1" errors="1" failures="0" skipped="0" | |
375 | + """ | |
376 | + # -- HINT FOR: Python < 3.8 | |
377 | + # <testsuite errors="1" failures="0" name="after_scenario_failure.Bob" skipped="0" tests="1" | |
378 | + And the file "reports/TESTS-after_scenario_failure.xml" should contain: | |
379 | + """ | |
380 | + <error type="RuntimeError" message="HOOK-ERROR in after_scenario: RuntimeError: OOPS"> | |
381 | + """ | |
382 | + # -- HINT FOR: Python < 3.8 | |
383 | + # <error message="HOOK-ERROR in after_scenario: RuntimeError: OOPS" type="RuntimeError"> | |
384 | + And the file "reports/TESTS-after_scenario_failure.xml" should contain: | |
385 | + """ | |
386 | + File "features/environment.py", line 10, in after_scenario | |
387 | + cause_hook_failure() | |
388 | + File "features/environment.py", line 2, in cause_hook_failure | |
389 | + raise RuntimeError("OOPS") | |
390 | + """ | |
391 | + And note that "the traceback is contained in the XML element <error/>" | |
392 | diff --git a/issue.features/issue0457.feature b/issue.features/issue0457.feature | |
393 | index f80640e9..46f96e9c 100644 | |
394 | --- a/issue.features/issue0457.feature | |
395 | +++ b/issue.features/issue0457.feature | |
396 | @@ -24,6 +24,7 @@ Feature: Issue #457 -- Double-quotes in error messages of JUnit XML reports | |
397 | """ | |
398 | ||
399 | ||
400 | + @not.with_python.version=3.8 | |
401 | Scenario: Use failing assertation in a JUnit XML report | |
402 | Given a file named "features/fails1.feature" with: | |
403 | """ | |
404 | @@ -44,6 +45,31 @@ Feature: Issue #457 -- Double-quotes in error messages of JUnit XML reports | |
405 | <failure message="FAILED: My name is "Alice"" | |
406 | """ | |
407 | ||
408 | + @use.with_python.version=3.8 | |
409 | + Scenario: Use failing assertation in a JUnit XML report | |
410 | + Given a file named "features/fails1.feature" with: | |
411 | + """ | |
412 | + Feature: | |
413 | + Scenario: Alice | |
414 | + Given a step fails with message: | |
415 | + ''' | |
416 | + My name is "Alice" | |
417 | + ''' | |
418 | + """ | |
419 | + When I run "behave --junit features/fails1.feature" | |
420 | + Then it should fail with: | |
421 | + """ | |
422 | + 0 scenarios passed, 1 failed, 0 skipped | |
423 | + """ | |
424 | + And the file "reports/TESTS-fails1.xml" should contain: | |
425 | + """ | |
426 | + <failure type="AssertionError" message="FAILED: My name is "Alice""> | |
427 | + """ | |
428 | + # -- HINT FOR: Python < 3.8 | |
429 | + # <failure message="FAILED: My name is "Alice"" | |
430 | + | |
431 | + | |
432 | + @not.with_python.version=3.8 | |
433 | Scenario: Use exception in a JUnit XML report | |
434 | Given a file named "features/fails2.feature" with: | |
435 | """ | |
436 | @@ -63,3 +89,26 @@ Feature: Issue #457 -- Double-quotes in error messages of JUnit XML reports | |
437 | """ | |
438 | <error message="My name is "Bob" and <here> I am" | |
439 | """ | |
440 | + | |
441 | + @use.with_python.version=3.8 | |
442 | + Scenario: Use exception in a JUnit XML report | |
443 | + Given a file named "features/fails2.feature" with: | |
444 | + """ | |
445 | + Feature: | |
446 | + Scenario: Bob | |
447 | + Given a step fails with error and message: | |
448 | + ''' | |
449 | + My name is "Bob" and <here> I am | |
450 | + ''' | |
451 | + """ | |
452 | + When I run "behave --junit features/fails2.feature" | |
453 | + Then it should fail with: | |
454 | + """ | |
455 | + 0 scenarios passed, 1 failed, 0 skipped | |
456 | + """ | |
457 | + And the file "reports/TESTS-fails2.xml" should contain: | |
458 | + """ | |
459 | + <error type="RuntimeError" message="My name is "Bob" and <here> I am"> | |
460 | + """ | |
461 | + # -- HINT FOR: Python < 3.8 | |
462 | + # <error message="My name is "Bob" and <here> I am" |