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
|
Feature: Use logging_filter with logcapture
PRECONDITION: log_capture mode is enabled (config.log_capture = true).
As a tester
In log-capture mode
I want to include/exclude log-records from some logging categories
So that the output is not cluttered with unneeded information in case of failures.
Background:
Given I define the log record schema:
| category | level | message |
| root | ERROR | __LOG_MESSAGE__ |
@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/logging.failing_example.feature" with:
"""
Feature:
Scenario: Failing
Given I create log records with:
| category | level | message |
| root | ERROR | __LOG_MESSAGE__ |
| foo | ERROR | __LOG_MESSAGE__ |
| foo.bar | ERROR | __LOG_MESSAGE__ |
| bar | ERROR | __LOG_MESSAGE__ |
When another step fails
"""
And a file named "behave.ini" with:
"""
[behave]
log_capture = true
logging_level = WARN
"""
Scenario: Include only a logging category
When I run "behave --logcapture --logging-filter=foo features/logging.failing_example.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 log records from categories:
| category |
| foo |
But the command output should not contain log records from categories:
| category | Comment |
| root | Not included: filtered-out |
| foo.bar | Not included: filtered-out |
| bar | Not included: filtered-out |
Scenario: Include only a logging sub-category
When I run "behave --logcapture --logging-filter=foo.bar features/logging.failing_example.feature"
Then it should fail
And the command output should contain log records from categories:
| category | Comment |
| foo.bar | Included |
But the command output should not contain log records from categories:
| category | Comment |
| root | Not included: filtered-out |
| foo | Not included: filtered-out |
| bar | Not included: filtered-out |
Scenario: Exclude a logging category
When I run "behave --logcapture --logging-filter=-foo features/logging.failing_example.feature"
Then it should fail
And the command output should contain log records from categories:
| category | Comment |
| root | Not excluded: foo |
| foo.bar | Not excluded: foo |
| bar | Not excluded: foo |
But the command output should not contain log records from categories:
| category | Comment |
| foo | Excluded |
Scenario: Include several logging categories
When I run "behave --logcapture --logging-filter=foo,bar features/logging.failing_example.feature"
Then it should fail
And the command output should contain log records from categories:
| category | Comment |
| foo | Included: foo |
| bar | Included: bar |
But the command output should not contain log records from categories:
| category | Comment |
| root | Not included: filtered-out |
| foo.bar | Not included (sub-category) |
Scenario: Include/exclude several logging categories
When I run "behave --logcapture --logging-filter=foo.bar,-bar features/logging.failing_example.feature"
Then it should fail
And the command output should contain log records from categories:
| category | Comment |
| root | Not excluded: bar |
| foo | Not excluded: bar |
| foo.bar | Included |
But the command output should not contain log records from categories:
| category | Comment |
| bar | Excluded: filtered-out |
Scenario: Include/exclude several logging categories with configfile
Given a file named "behave.ini" with:
"""
[behave]
log_capture = true
logging_level = WARN
logging_filter = foo.bar,-bar
"""
When I run "behave --logcapture features/logging.failing_example.feature"
Then it should fail
And the command output should contain log records from categories:
| category | Comment |
| root | Not excluded: bar |
| foo | Not excluded: bar |
| foo.bar | Included |
But the command output should not contain log records from categories:
| category | Comment |
| bar | Excluded: filtered-out |
|