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 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
|
@logging
@capture
Feature: Capture log output
As a tester
I want that log output is captured
But log-records are only shown when failures/errors occur
So that failure diagnostics are simplified
. SPECIFICATION:
. * log_capture mode is enabled per default
. * log_capture mode can be defined on command-line
. * log_capture mode can be defined in behave configuration file
. * In log_capture mode: Captured log-records are only shown if a scenario fails
.
. RELATED:
. * logcapture.*.feature
. * logging.*.feature
@setup
Scenario: Feature Setup
Given a new working directory
And a file named "features/steps/use_behave4cmd_steps.py" with:
"""
import behave4cmd0.log.steps
import behave4cmd0.failing_steps
import behave4cmd0.passing_steps
"""
And a file named "features/environment.py" with:
"""
def before_all(context):
context.config.setup_logging()
# -- SAME-AS:
# import logging
# logging.basicConfig(level=context.config.logging_level)
"""
And a file named "features/example.log_and_pass.feature" with:
"""
Feature:
Scenario: Passing
Given I create log records with:
| category | level | message |
| root | FATAL | Hello Alice |
| foo | ERROR | Hello Bob |
| foo.bar | WARN | Hello Charly |
| bar | INFO | Hello Dora |
| baz | DEBUG | Hello Emily |
When another step passes
"""
And a file named "features/example.log_and_fail.feature" with:
"""
Feature:
Scenario: Failing
Given I create log records with:
| category | level | message |
| root | FATAL | Hello Alice |
| foo | ERROR | Hello Bob |
| foo.bar | WARN | Hello Charly |
| bar | INFO | Hello Dora |
| baz | DEBUG | Hello Emily |
When another step fails
"""
Scenario: Captured log is suppressed if scenario passes
When I run "behave -f plain -T --logcapture features/example.log_and_pass.feature"
Then it should pass with:
"""
1 scenario passed, 0 failed, 0 skipped
2 steps passed, 0 failed, 0 skipped, 0 undefined
"""
And the command output should contain:
"""
Scenario: Passing
Given I create log records with ... passed
| category | level | message |
| root | FATAL | Hello Alice |
| foo | ERROR | Hello Bob |
| foo.bar | WARN | Hello Charly |
| bar | INFO | Hello Dora |
| baz | DEBUG | Hello Emily |
When another step passes ... passed
"""
And the command output should not contain:
"""
Captured logging:
"""
But the command output should not contain the following log records:
| category | level | message |
| root | FATAL | Hello Alice |
| foo | ERROR | Hello Bob |
| foo.bar | WARN | Hello Charly |
| bar | INFO | Hello Dora |
| baz | DEBUG | Hello Emily |
Scenario: Captured log is shown up to first failure if scenario fails
When I run "behave -f plain -T --logcapture features/example.log_and_fail.feature"
Then it should fail with:
"""
0 scenarios passed, 1 failed, 0 skipped
1 step passed, 1 failed, 0 skipped, 0 undefined
"""
And the command output should contain:
"""
Feature:
Scenario: Failing
Given I create log records with ... passed
| category | level | message |
| root | FATAL | Hello Alice |
| foo | ERROR | Hello Bob |
| foo.bar | WARN | Hello Charly |
| bar | INFO | Hello Dora |
| baz | DEBUG | Hello Emily |
When another step fails ... failed
Assertion Failed: EXPECT: Failing step
Captured logging:
CRITICAL:root:Hello Alice
ERROR:foo:Hello Bob
WARNING:foo.bar:Hello Charly
INFO:bar:Hello Dora
"""
And the command output should contain the following log records:
| category | level | message |
| root | FATAL | Hello Alice |
| foo | ERROR | Hello Bob |
| foo.bar | WARN | Hello Charly |
| bar | INFO | Hello Dora |
But the command output should not contain the following log records:
| category | level | message | Comment |
| baz | DEBUG | Hello Emily | Log-level too low: filtered-out |
Scenario: Captured log is shown up to first failure if log_record.level is not too low
Ensure that only log-records are shown that exceed the logging-level.
When I run "behave -f plain --logcapture --logging-level=ERROR features/example.log_and_fail.feature"
Then it should fail
And the command output should contain the following log records:
| category | level | message |
| root | FATAL | Hello Alice |
| foo | ERROR | Hello Bob |
But the command output should not contain the following log records:
| category | level | message |
| foo.bar | WARN | Hello Charly |
| bar | INFO | Hello Dora |
| baz | DEBUG | Hello Emily |
Scenario: Logcapture mode is enabled per default
When I run "behave -f plain features/example.log_and_fail.feature"
Then it should fail
And the command output should contain "Captured logging:"
Scenario: Logcapture mode can be enabled on command-line
When I run "behave -f plain --logcapture features/example.log_and_fail.feature"
Then it should fail
And the command output should contain "Captured logging:"
Scenario: Logcapture mode can be disabled on command-line
When I run "behave -f plain --no-logcapture features/example.log_and_fail.feature"
Then it should fail
And the command output should not contain "Captured logging:"
Scenario: Logcapture mode can be enabled in configfile
Given a file named "behave.ini" with:
"""
[behave]
log_capture = true
"""
When I run "behave -f plain features/example.log_and_fail.feature"
Then it should fail
And the command output should contain "Captured logging:"
Scenario: Logcapture mode can be disabled in configfile
Given a file named "behave.ini" with:
"""
[behave]
log_capture = false
"""
When I run "behave -f plain features/example.log_and_fail.feature"
Then it should fail
And the command output should not contain "Captured logging:"
|