| 1 |
Feature: Use logging_filter with logcapture |
| 2 |
|
| 3 |
PRECONDITION: log_capture mode is enabled (config.log_capture = true). |
| 4 |
|
| 5 |
As a tester |
| 6 |
In log-capture mode |
| 7 |
I want to include/exclude log-records from some logging categories |
| 8 |
So that the output is not cluttered with unneeded information in case of failures. |
| 9 |
|
| 10 |
Background: |
| 11 |
Given I define the log record schema: |
| 12 |
| category | level | message | |
| 13 |
| root | ERROR | __LOG_MESSAGE__ | |
| 14 |
|
| 15 |
@setup |
| 16 |
Scenario: Feature Setup |
| 17 |
Given a new working directory |
| 18 |
And a file named "features/steps/use_behave4cmd_steps.py" with: |
| 19 |
""" |
| 20 |
import behave4cmd0.log.steps |
| 21 |
import behave4cmd0.failing_steps |
| 22 |
import behave4cmd0.passing_steps |
| 23 |
""" |
| 24 |
And a file named "features/logging.failing_example.feature" with: |
| 25 |
""" |
| 26 |
Feature: |
| 27 |
Scenario: Failing |
| 28 |
Given I create log records with: |
| 29 |
| category | level | message | |
| 30 |
| root | ERROR | __LOG_MESSAGE__ | |
| 31 |
| foo | ERROR | __LOG_MESSAGE__ | |
| 32 |
| foo.bar | ERROR | __LOG_MESSAGE__ | |
| 33 |
| bar | ERROR | __LOG_MESSAGE__ | |
| 34 |
When another step fails |
| 35 |
""" |
| 36 |
And a file named "behave.ini" with: |
| 37 |
""" |
| 38 |
[behave] |
| 39 |
log_capture = true |
| 40 |
logging_level = WARN |
| 41 |
""" |
| 42 |
|
| 43 |
|
| 44 |
Scenario: Include only a logging category |
| 45 |
When I run "behave --logcapture --logging-filter=foo features/logging.failing_example.feature" |
| 46 |
Then it should fail with: |
| 47 |
""" |
| 48 |
0 scenarios passed, 1 failed, 0 skipped |
| 49 |
1 step passed, 1 failed, 0 skipped, 0 undefined |
| 50 |
""" |
| 51 |
And the command output should contain log records from categories: |
| 52 |
| category | |
| 53 |
| foo | |
| 54 |
But the command output should not contain log records from categories: |
| 55 |
| category | Comment | |
| 56 |
| root | Not included: filtered-out | |
| 57 |
| foo.bar | Not included: filtered-out | |
| 58 |
| bar | Not included: filtered-out | |
| 59 |
|
| 60 |
|
| 61 |
Scenario: Include only a logging sub-category |
| 62 |
When I run "behave --logcapture --logging-filter=foo.bar features/logging.failing_example.feature" |
| 63 |
Then it should fail |
| 64 |
And the command output should contain log records from categories: |
| 65 |
| category | Comment | |
| 66 |
| foo.bar | Included | |
| 67 |
But the command output should not contain log records from categories: |
| 68 |
| category | Comment | |
| 69 |
| root | Not included: filtered-out | |
| 70 |
| foo | Not included: filtered-out | |
| 71 |
| bar | Not included: filtered-out | |
| 72 |
|
| 73 |
|
| 74 |
Scenario: Exclude a logging category |
| 75 |
When I run "behave --logcapture --logging-filter=-foo features/logging.failing_example.feature" |
| 76 |
Then it should fail |
| 77 |
And the command output should contain log records from categories: |
| 78 |
| category | Comment | |
| 79 |
| root | Not excluded: foo | |
| 80 |
| foo.bar | Not excluded: foo | |
| 81 |
| bar | Not excluded: foo | |
| 82 |
But the command output should not contain log records from categories: |
| 83 |
| category | Comment | |
| 84 |
| foo | Excluded | |
| 85 |
|
| 86 |
|
| 87 |
Scenario: Include several logging categories |
| 88 |
When I run "behave --logcapture --logging-filter=foo,bar features/logging.failing_example.feature" |
| 89 |
Then it should fail |
| 90 |
And the command output should contain log records from categories: |
| 91 |
| category | Comment | |
| 92 |
| foo | Included: foo | |
| 93 |
| bar | Included: bar | |
| 94 |
But the command output should not contain log records from categories: |
| 95 |
| category | Comment | |
| 96 |
| root | Not included: filtered-out | |
| 97 |
| foo.bar | Not included (sub-category) | |
| 98 |
|
| 99 |
|
| 100 |
Scenario: Include/exclude several logging categories |
| 101 |
When I run "behave --logcapture --logging-filter=foo.bar,-bar features/logging.failing_example.feature" |
| 102 |
Then it should fail |
| 103 |
And the command output should contain log records from categories: |
| 104 |
| category | Comment | |
| 105 |
| root | Not excluded: bar | |
| 106 |
| foo | Not excluded: bar | |
| 107 |
| foo.bar | Included | |
| 108 |
But the command output should not contain log records from categories: |
| 109 |
| category | Comment | |
| 110 |
| bar | Excluded: filtered-out | |
| 111 |
|
| 112 |
|
| 113 |
Scenario: Include/exclude several logging categories with configfile |
| 114 |
Given a file named "behave.ini" with: |
| 115 |
""" |
| 116 |
[behave] |
| 117 |
log_capture = true |
| 118 |
logging_level = WARN |
| 119 |
logging_filter = foo.bar,-bar |
| 120 |
""" |
| 121 |
When I run "behave --logcapture features/logging.failing_example.feature" |
| 122 |
Then it should fail |
| 123 |
And the command output should contain log records from categories: |
| 124 |
| category | Comment | |
| 125 |
| root | Not excluded: bar | |
| 126 |
| foo | Not excluded: bar | |
| 127 |
| foo.bar | Included | |
| 128 |
But the command output should not contain log records from categories: |
| 129 |
| category | Comment | |
| 130 |
| bar | Excluded: filtered-out | |