| 1 |
Feature: Setup logging subsystem by using a logging configfile |
| 2 |
|
| 3 |
As a tester |
| 4 |
I want to setup the logging subsystem by using a configfile |
| 5 |
To be more flexible even in complex situations |
| 6 |
|
| 7 |
@setup |
| 8 |
Scenario: Feature setup |
| 9 |
Given a new working directory |
| 10 |
And a file named "features/steps/use_behave4cmd_steps.py" with: |
| 11 |
""" |
| 12 |
import behave4cmd0.log.steps |
| 13 |
import behave4cmd0.failing_steps |
| 14 |
import behave4cmd0.passing_steps |
| 15 |
""" |
| 16 |
And a file named "features/example.log_and_pass.feature" with: |
| 17 |
""" |
| 18 |
Feature: |
| 19 |
Scenario: Passing |
| 20 |
Given I create log records with: |
| 21 |
| category | level | message | |
| 22 |
| root | FATAL | Hello Alice | |
| 23 |
| foo | ERROR | Hello Bob | |
| 24 |
| foo.bar | WARN | Hello Charly | |
| 25 |
| bar | INFO | Hello Dora | |
| 26 |
| baz | DEBUG | Hello Emily | |
| 27 |
And another step passes |
| 28 |
""" |
| 29 |
And a file named "features/example.log_and_fail.feature" with: |
| 30 |
""" |
| 31 |
Feature: |
| 32 |
Scenario: Failing |
| 33 |
Given I create log records with: |
| 34 |
| category | level | message | |
| 35 |
| root | FATAL | Hello Alice | |
| 36 |
| foo | ERROR | Hello Bob | |
| 37 |
| foo.bar | WARN | Hello Charly | |
| 38 |
| bar | INFO | Hello Dora | |
| 39 |
| baz | DEBUG | Hello Emily | |
| 40 |
And another step fails |
| 41 |
""" |
| 42 |
And a file named "behave.ini" with: |
| 43 |
""" |
| 44 |
[behave] |
| 45 |
log_capture = false |
| 46 |
logging_level = DEBUG |
| 47 |
logging_format = LOG.%(levelname)-8s %(name)-10s: %(message)s |
| 48 |
""" |
| 49 |
And a file named "behave_logging.ini" with: |
| 50 |
""" |
| 51 |
[loggers] |
| 52 |
keys=root |
| 53 |
|
| 54 |
[handlers] |
| 55 |
keys=Console,File |
| 56 |
|
| 57 |
[formatters] |
| 58 |
keys=Brief |
| 59 |
|
| 60 |
[logger_root] |
| 61 |
level = NOTSET |
| 62 |
handlers = File |
| 63 |
# handlers = Console,File |
| 64 |
|
| 65 |
[handler_File] |
| 66 |
class=FileHandler |
| 67 |
args=("behave.log", 'w') |
| 68 |
level=NOTSET |
| 69 |
formatter=Brief |
| 70 |
|
| 71 |
[handler_Console] |
| 72 |
class=StreamHandler |
| 73 |
args=(sys.stderr,) |
| 74 |
level=NOTSET |
| 75 |
formatter=Brief |
| 76 |
|
| 77 |
[formatter_Brief] |
| 78 |
format= LOG.%(levelname)-8s %(name)-10s: %(message)s |
| 79 |
datefmt= |
| 80 |
""" |
| 81 |
|
| 82 |
Scenario: Setup logging subsystem via environment (case: logging mode) |
| 83 |
Given a file named "features/environment.py" with: |
| 84 |
""" |
| 85 |
def before_all(context): |
| 86 |
context.config.setup_logging(configfile="behave_logging.ini") |
| 87 |
""" |
| 88 |
And I use the log record configuration: |
| 89 |
| property | value | |
| 90 |
| format | LOG.%(levelname)-8s %(name)-10s: %(message)s | |
| 91 |
When I run "behave -f plain features/example.log_and_pass.feature" |
| 92 |
Then it should pass |
| 93 |
And the file "behave.log" should contain the log records: |
| 94 |
| category | level | message | |
| 95 |
| root | FATAL | Hello Alice | |
| 96 |
| foo | ERROR | Hello Bob | |
| 97 |
| foo.bar | WARN | Hello Charly | |
| 98 |
| bar | INFO | Hello Dora | |
| 99 |
| baz | DEBUG | Hello Emily | |
| 100 |
And the command output should not contain the following log records: |
| 101 |
| category | level | message | |
| 102 |
| root | FATAL | Hello Alice | |
| 103 |
| foo | ERROR | Hello Bob | |
| 104 |
| foo.bar | WARN | Hello Charly | |
| 105 |
| bar | INFO | Hello Dora | |
| 106 |
| baz | DEBUG | Hello Emily | |
| 107 |
|
| 108 |
|
| 109 |
Scenario: Setup logging subsystem via environment (case: log-capture mode) |
| 110 |
Given a file named "features/environment.py" with: |
| 111 |
""" |
| 112 |
def before_all(context): |
| 113 |
context.config.setup_logging(configfile="behave_logging.ini") |
| 114 |
""" |
| 115 |
And I use the log record configuration: |
| 116 |
| property | value | |
| 117 |
| format | LOG.%(levelname)-8s %(name)-10s: %(message)s | |
| 118 |
When I run "behave -f plain --logcapture features/example.log_and_fail.feature" |
| 119 |
Then it should fail with: |
| 120 |
""" |
| 121 |
0 scenarios passed, 1 failed, 0 skipped |
| 122 |
1 step passed, 1 failed, 0 skipped, 0 undefined |
| 123 |
""" |
| 124 |
And the file "behave.log" should contain the log records: |
| 125 |
| category | level | message | |
| 126 |
| root | FATAL | Hello Alice | |
| 127 |
| foo | ERROR | Hello Bob | |
| 128 |
| foo.bar | WARN | Hello Charly | |
| 129 |
| bar | INFO | Hello Dora | |
| 130 |
| baz | DEBUG | Hello Emily | |
| 131 |
And the command output should contain the following log records: |
| 132 |
| category | level | message | |
| 133 |
| root | FATAL | Hello Alice | |
| 134 |
| foo | ERROR | Hello Bob | |
| 135 |
| foo.bar | WARN | Hello Charly | |
| 136 |
| bar | INFO | Hello Dora | |
| 137 |
| baz | DEBUG | Hello Emily | |