Debian Codegraph @

issue.features/issue0446.feature

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
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 Scenario: Hook error in before_scenario()
62 When I run "behave -f plain --junit features/before_scenario_failure.feature"
63 Then it should fail with:
64 """
65 0 scenarios passed, 1 failed, 0 skipped
66 """
67 And the command output should contain:
68 """
69 HOOK-ERROR in before_scenario: RuntimeError: OOPS
70 """
71 And the file "reports/TESTS-before_scenario_failure.xml" should contain:
72 """
73 <testsuite errors="1" failures="0" name="before_scenario_failure.Alice" skipped="0" tests="1"
74 """
75 And the file "reports/TESTS-before_scenario_failure.xml" should contain:
76 """
77 <error message="HOOK-ERROR in before_scenario: RuntimeError: OOPS" type="RuntimeError">
78 """
79 And the file "reports/TESTS-before_scenario_failure.xml" should contain:
80 """
81 File "features/environment.py", line 6, in before_scenario
82 cause_hook_failure()
83 File "features/environment.py", line 2, in cause_hook_failure
84 raise RuntimeError("OOPS")
85 """
86 And note that "the traceback is contained in the XML element <error/>"
87
88
89 Scenario: Hook error in after_scenario()
90 When I run "behave -f plain --junit features/after_scenario_failure.feature"
91 Then it should fail with:
92 """
93 0 scenarios passed, 1 failed, 0 skipped
94 """
95 And the command output should contain:
96 """
97 Scenario: B1
98 Given another step passes ... passed
99 HOOK-ERROR in after_scenario: RuntimeError: OOPS
100 """
101 And the file "reports/TESTS-after_scenario_failure.xml" should contain:
102 """
103 <testsuite errors="1" failures="0" name="after_scenario_failure.Bob" skipped="0" tests="1"
104 """
105 And the file "reports/TESTS-after_scenario_failure.xml" should contain:
106 """
107 <error message="HOOK-ERROR in after_scenario: RuntimeError: OOPS" type="RuntimeError">
108 """
109 And the file "reports/TESTS-after_scenario_failure.xml" should contain:
110 """
111 File "features/environment.py", line 10, in after_scenario
112 cause_hook_failure()
113 File "features/environment.py", line 2, in cause_hook_failure
114 raise RuntimeError("OOPS")
115 """
116 And note that "the traceback is contained in the XML element <error/>"