Debian Codegraph @

features/capture_stdout.feature

raw
1 @sequential
2 Feature: Capture stdout 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
12 @setup
13 Scenario: Test Setup
14 Given a new working directory
15 And a file named "features/steps/stdout_steps.py" with:
16 """
17 from behave import step
18 import sys
19
20 @step('a step writes "{text}" to stdout and passes')
21 def step_writes_to_stdout_and_passes(context, text):
22 sys.stdout.write("stdout:%s;\n" % text)
23
24 @step('a step writes "{text}" to stdout and fails')
25 def step_writes_to_stdout_and_fails(context, text):
26 sys.stdout.write("stdout:%s;\n" % text)
27 assert False, "XFAIL, step with: %s;" % text
28 """
29 And a file named "features/capture_stdout.example1.feature" with:
30 """
31 Feature:
32 Scenario:
33 Given a step writes "Alice" to stdout and passes
34 When a step writes "Bob" to stdout and passes
35 Then a step writes "Charly" to stdout and passes
36 """
37 And a file named "features/capture_stdout.example2.feature" with:
38 """
39 Feature:
40 Scenario:
41 Given a step writes "Alice" to stdout and passes
42 When a step writes "Bob" to stdout and fails
43 Then a step writes "Charly" to stdout and fails
44 """
45
46
47 @capture
48 Scenario: Captured output is suppressed if scenario passes
49 When I run "behave -f plain -T --capture features/capture_stdout.example1.feature"
50 Then it should pass
51 And the command output should contain:
52 """
53 Feature:
54 Scenario:
55 Given a step writes "Alice" to stdout and passes ... passed
56 When a step writes "Bob" to stdout and passes ... passed
57 Then a step writes "Charly" to stdout and passes ... passed
58 """
59 But the command output should not contain:
60 """
61 stdout:Alice;
62 """
63
64 @capture
65 Scenario: Captured output is shown up to first failure if scenario fails
66 When I run "behave -f plain -T --capture features/capture_stdout.example2.feature"
67 Then it should fail with:
68 """
69 0 scenarios passed, 1 failed, 0 skipped
70 1 step passed, 1 failed, 1 skipped, 0 undefined
71 """
72 And the command output should contain:
73 """
74 Feature:
75 Scenario:
76 Given a step writes "Alice" to stdout and passes ... passed
77 When a step writes "Bob" to stdout and fails ... failed
78 Assertion Failed: XFAIL, step with: Bob;
79 Captured stdout:
80 stdout:Alice;
81 stdout:Bob;
82 """
83 But the command output should not contain:
84 """
85 stdout:Charly;
86 """
87
88 @no_capture
89 Scenario: All output is shown when --no-capture is used and all steps pass (CASE 1)
90 When I run "behave -f plain -T --no-capture features/capture_stdout.example1.feature"
91 Then it should pass
92 And the command output should contain:
93 """
94 Feature:
95 Scenario:
96 stdout:Alice;
97 Given a step writes "Alice" to stdout and passes ... passed
98 stdout:Bob;
99 When a step writes "Bob" to stdout and passes ... passed
100 stdout:Charly;
101 Then a step writes "Charly" to stdout and passes ... passed
102 """
103
104
105 @no_capture
106 Scenario: All output is shown up to first failing step when --no-capture is used (CASE 2)
107 When I run "behave -f plain -T --no-capture features/capture_stdout.example2.feature"
108 Then it should fail with:
109 """
110 0 scenarios passed, 1 failed, 0 skipped
111 1 step passed, 1 failed, 1 skipped, 0 undefined
112 """
113 And the command output should contain:
114 """
115 Feature:
116 Scenario:
117 stdout:Alice;
118 Given a step writes "Alice" to stdout and passes ... passed
119 stdout:Bob;
120 When a step writes "Bob" to stdout and fails ... failed
121 """
122 But the command output should not contain:
123 """
124 stdout:Charly;
125 """