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