Debian Codegraph @

features/capture_stderr.feature

raw
1 @sequential
2 Feature: Capture stderr output and show it in case of failures/errors
3
4 As a tester
5 To simplify failure diagnostics
6 I want that:
7 - captured output is displayed only when failures/errors occur
8 - all output is displayed when capture is disabled
9 (but may clutter up formatter output)
10
11 @setup
12 Scenario: Test Setup
13 Given a new working directory
14 And a file named "features/steps/stderr_steps.py" with:
15 """
16 from behave import step
17 import sys
18
19 @step('a step writes "{text}" to stderr and passes')
20 def step_writes_to_stderr_and_passes(context, text):
21 sys.stderr.write("stderr:%s;\n" % text)
22
23 @step('a step writes "{text}" to stderr and fails')
24 def step_writes_to_stderr_and_fails(context, text):
25 sys.stderr.write("stderr:%s;\n" % text)
26 assert False, "XFAIL, step with: %s;" % text
27 """
28 And a file named "features/capture_stderr.example1.feature" with:
29 """
30 Feature:
31 Scenario:
32 Given a step writes "Alice" to stderr and passes
33 When a step writes "Bob" to stderr and passes
34 Then a step writes "Charly" to stderr and passes
35 """
36 And a file named "features/capture_stderr.example2.feature" with:
37 """
38 Feature:
39 Scenario:
40 Given a step writes "Alice" to stderr and passes
41 When a step writes "Bob" to stderr and fails
42 Then a step writes "Charly" to stderr and fails
43 """
44
45
46 @capture
47 Scenario: Captured output is suppressed if scenario passes (CASE 1: --capture)
48 When I run "behave -f plain -T --capture features/capture_stderr.example1.feature"
49 Then it should pass
50 And the command output should contain:
51 """
52 Feature:
53 Scenario:
54 Given a step writes "Alice" to stderr and passes ... passed
55 When a step writes "Bob" to stderr and passes ... passed
56 Then a step writes "Charly" to stderr and passes ... passed
57 """
58 But the command output should not contain:
59 """
60 stderr:Alice;
61 """
62
63 @capture
64 Scenario: Captured output is suppressed if scenario passes (CASE 2: --capture-stderr)
65 When I run "behave -f plain -T --capture-stderr features/capture_stderr.example1.feature"
66 Then it should pass
67 And the command output should contain:
68 """
69 Feature:
70 Scenario:
71 Given a step writes "Alice" to stderr and passes ... passed
72 When a step writes "Bob" to stderr and passes ... passed
73 Then a step writes "Charly" to stderr and passes ... passed
74 """
75 But the command output should not contain:
76 """
77 stderr:Alice;
78 """
79
80 @capture
81 Scenario: Captured output is shown up to first failure if scenario fails (CASE 1: --capture)
82 When I run "behave -f plain -T --capture features/capture_stderr.example2.feature"
83 Then it should fail with:
84 """
85 0 scenarios passed, 1 failed, 0 skipped
86 1 step passed, 1 failed, 1 skipped, 0 undefined
87 """
88 And the command output should contain:
89 """
90 Feature:
91 Scenario:
92 Given a step writes "Alice" to stderr and passes ... passed
93 When a step writes "Bob" to stderr and fails ... failed
94 Assertion Failed: XFAIL, step with: Bob;
95 Captured stderr:
96 stderr:Alice;
97 stderr:Bob;
98 """
99 But the command output should not contain:
100 """
101 stderr:Charly;
102 """
103
104 @capture
105 Scenario: Captured output is shown if scenario fails up to first failure (CASE 2: --capture-stderr)
106 When I run "behave -f plain -T --capture-stderr features/capture_stderr.example2.feature"
107 Then it should fail with:
108 """
109 0 scenarios passed, 1 failed, 0 skipped
110 1 step passed, 1 failed, 1 skipped, 0 undefined
111 """
112 And the command output should contain:
113 """
114 Feature:
115 Scenario:
116 Given a step writes "Alice" to stderr and passes ... passed
117 When a step writes "Bob" to stderr and fails ... failed
118 Assertion Failed: XFAIL, step with: Bob;
119 Captured stderr:
120 stderr:Alice;
121 stderr:Bob;
122 """
123 But the command output should not contain:
124 """
125 stderr:Charly;
126 """
127
128 @no_capture
129 Scenario: All output is shown when --no-capture-stderr is used and all steps pass (CASE 1)
130 When I run "behave -f plain -T --no-capture-stderr features/capture_stderr.example1.feature"
131 Then it should pass
132 And the command output should contain:
133 """
134 stderr:Alice;
135 stderr:Bob;
136 stderr:Charly;
137 """
138 And the command output should contain:
139 """
140 Feature:
141 Scenario:
142 Given a step writes "Alice" to stderr and passes ... passed
143 When a step writes "Bob" to stderr and passes ... passed
144 Then a step writes "Charly" to stderr and passes ... passed
145 """
146
147
148 @no_capture
149 Scenario: All output is shown up to first failing step when --no-capture-stderr is used (CASE 2)
150 When I run "behave -f plain -T --no-capture-stderr features/capture_stderr.example2.feature"
151 Then it should fail with:
152 """
153 0 scenarios passed, 1 failed, 0 skipped
154 1 step passed, 1 failed, 1 skipped, 0 undefined
155 """
156 And the command output should contain:
157 """
158 Feature:
159 Scenario:
160 Given a step writes "Alice" to stderr and passes ... passed
161 When a step writes "Bob" to stderr and fails ... failed
162 Assertion Failed: XFAIL, step with: Bob;
163 """
164 And the command output should contain:
165 """
166 stderr:Alice;
167 stderr:Bob;
168 """
169 But the command output should not contain:
170 """
171 stderr:Charly;
172 """