Debian Codegraph @

features/logging.setup_format.feature

raw
1 Feature: Setup logging_format
2
3 As a tester
4 I want to configure the logging_format for log_capture mode
5 So that log-records are shown in my preferred format.
6
7 As a tester
8 I want to configure the logging_format for logging mode (no-log_capture)
9 So that log-records are shown in my preferred format.
10
11 . SPECIFICATION:
12 . * logging_format can be defined on command-line
13 . * logging_format can be defined in behave configuration file
14 .
15 . NOTE:
16 . The log record format can also be defined in a logging configuration file.
17
18 @setup
19 Scenario: Feature Setup
20 Given a new working directory
21 And a file named "features/steps/use_behave4cmd_steps.py" with:
22 """
23 import behave4cmd0.log.steps
24 import behave4cmd0.failing_steps
25 import behave4cmd0.passing_steps
26 """
27 And a file named "features/environment.py" with:
28 """
29 def before_all(context):
30 context.config.setup_logging()
31 """
32 And a file named "features/example.log_and_fail.feature" with:
33 """
34 Feature:
35 Scenario: Failing
36 Given I create log records with:
37 | category | level | message |
38 | root | ERROR | Hello Alice |
39 | root | WARN | Hello Bob |
40 When a step fails
41 """
42
43 @capture
44 Scenario: Use logging_format on command-line (case: log_capture mode)
45 Given a file named "behave.ini" with:
46 """
47 [behave]
48 log_capture = true
49 logging_level = WARN
50 """
51 When I run "behave -f plain -T --logging-format='LOG.%(levelname)-8s %(name)-10s: %(message)s' features/"
52 Then it should fail with:
53 """
54 0 scenarios passed, 1 failed, 0 skipped
55 1 step passed, 1 failed, 0 skipped, 0 undefined
56 """
57 And the command output should contain "Captured logging:"
58 And the command output should contain:
59 """
60 Captured logging:
61 LOG.ERROR root : Hello Alice
62 LOG.WARNING root : Hello Bob
63 """
64 When I use the log record configuration:
65 | property | value |
66 | format | LOG.%(levelname)-8s %(name)-10s: %(message)s |
67 Then the command output should contain the following log records:
68 | category | level | message |
69 | root | ERROR | Hello Alice |
70 | root | WARN | Hello Bob |
71
72
73 @capture
74 Scenario: Use logging_format in config-file (case: log_capture mode)
75 Given a file named "behave.ini" with:
76 """
77 [behave]
78 log_capture = true
79 logging_level = WARN
80 logging_format = LOG.%(levelname)-8s %(name)-10s: %(message)s
81 """
82 When I run "behave -f plain features/"
83 Then it should fail
84 And the command output should contain "Captured logging:"
85 And the command output should contain:
86 """
87 Captured logging:
88 LOG.ERROR root : Hello Alice
89 LOG.WARNING root : Hello Bob
90 """
91
92 @no_capture
93 Scenario: Use logging_format on command-line (case: logging mode)
94 Given a file named "behave.ini" with:
95 """
96 [behave]
97 log_capture = false
98 logging_level = WARN
99 """
100 When I run "behave -f plain -T --logging-format='LOG.%(levelname)-8s %(name)-10s: %(message)s' features/"
101 Then it should fail with:
102 """
103 0 scenarios passed, 1 failed, 0 skipped
104 1 step passed, 1 failed, 0 skipped, 0 undefined
105 """
106 And the command output should not contain "Captured logging:"
107 And the command output should contain:
108 """
109 LOG.ERROR root : Hello Alice
110 LOG.WARNING root : Hello Bob
111 """
112 When I use the log record configuration:
113 | property | value |
114 | format | LOG.%(levelname)-8s %(name)-10s: %(message)s |
115 Then the command output should contain the following log records:
116 | category | level | message |
117 | root | ERROR | Hello Alice |
118 | root | WARN | Hello Bob |
119
120
121 @no_capture
122 Scenario: Use logging_format in config-file (case: logging mode)
123 Given a file named "behave.ini" with:
124 """
125 [behave]
126 log_capture = false
127 logging_level = WARN
128 logging_format = LOG.%(levelname)-8s %(name)-10s: %(message)s
129 """
130 When I run "behave -f plain features/"
131 Then it should fail
132 And the command output should not contain "Captured logging:"
133 And the command output should contain:
134 """
135 LOG.ERROR root : Hello Alice
136 LOG.WARNING root : Hello Bob
137 """
138
139 @capture
140 Scenario: Use logging_datefmt in config-file
141
142 Ensure that "logging_datefmt" option can be used.
143
144 Given a file named "behave.ini" with:
145 """
146 [behave]
147 logging_format = %(asctime)s LOG.%(levelname)-8s %(name)s: %(message)s
148 logging_datefmt = %Y-%m-%dT%H:%M:%S
149 """
150 When I run "behave -f plain features/"
151 Then it should fail with:
152 """
153 0 scenarios passed, 1 failed, 0 skipped
154 1 step passed, 1 failed, 0 skipped, 0 undefined
155 """
156 And the command output should contain "LOG.ERROR root: Hello Alice"
157 And the command output should contain "LOG.WARNING root: Hello Bob"