Debian Codegraph @

features/logcapture.clear_handlers.feature

raw
1 @logging
2 @capture
3 Feature: Use --logging-clear-handlers configuration option
4
5 PRECONDITION: log_capture mode is enabled (config.log_capture = true).
6
7 As a tester
8 In log-capture mode
9 I want sometimes to remove any logging handler before capture starts
10 So that I have the log-records output under control.
11
12
13 @setup
14 Scenario: Feature Setup
15 Given a new working directory
16 And a file named "features/steps/use_behave4cmd_steps.py" with:
17 """
18 import behave4cmd0.log.steps
19 import behave4cmd0.failing_steps
20 import behave4cmd0.passing_steps
21 """
22 And a file named "features/environment.py" with:
23 """
24 def before_all(context):
25 # -- SAME-AS: context.config.setup_logging()
26 import logging
27 logging.basicConfig(level=context.config.logging_level)
28
29 # -- ADDITIONAL LOG-HANDLER: Which will be cleared.
30 format = "LOG-HANDLER2: %(name)s %(levelname)s: %(message)s;"
31 handler = logging.StreamHandler()
32 handler.setFormatter(logging.Formatter(format))
33 root_logger = logging.getLogger()
34 root_logger.addHandler(handler)
35 """
36 And a file named "features/example.log_with_failure.feature" with:
37 """
38 Feature:
39 Scenario: Failing
40 Given I create log records with:
41 | category | level | message |
42 | root | ERROR | Hello Alice |
43 | root | WARN | Hello Bob |
44 When a step fails
45 """
46
47
48 Scenario: Use logcapture mode without clearing existing log handlers
49 Given a file named "behave.ini" with:
50 """
51 [behave]
52 log_capture = true
53 logging_level = WARN
54 """
55 When I run "behave -f plain features/example.log_with_failure.feature"
56 Then it should fail with:
57 """
58 0 scenarios passed, 1 failed, 0 skipped
59 1 step passed, 1 failed, 0 skipped, 0 undefined
60 """
61 And the command output should contain:
62 """
63 Captured logging:
64 ERROR:root:Hello Alice
65 WARNING:root:Hello Bob
66 """
67 And the command output should contain:
68 """
69 LOG-HANDLER2: root ERROR: Hello Alice;
70 LOG-HANDLER2: root WARNING: Hello Bob;
71 """
72
73
74 Scenario: Use logcapture mode with clearing additional log handlers (case: command-line)
75 Given a file named "behave.ini" with:
76 """
77 [behave]
78 log_capture = true
79 logging_level = WARN
80 """
81 When I run "behave -f plain --logging-clear-handlers features/example.log_with_failure.feature"
82 Then it should fail with:
83 """
84 Captured logging:
85 ERROR:root:Hello Alice
86 WARNING:root:Hello Bob
87 """
88 But the command output should not contain:
89 """
90 LOG-HANDLER2: root ERROR: Hello Alice;
91 LOG-HANDLER2: root WARNING: Hello Bob;
92 """
93
94
95 Scenario: Use Logcapture mode with clearing additional log handlers (case: configfile)
96 Given a file named "behave.ini" with:
97 """
98 [behave]
99 log_capture = true
100 logging_level = WARN
101 logging_clear_handlers = true
102 """
103 When I run "behave -f plain features/example.log_with_failure.feature"
104 Then it should fail with:
105 """
106 Captured logging:
107 ERROR:root:Hello Alice
108 WARNING:root:Hello Bob
109 """
110 But the command output should not contain:
111 """
112 LOG-HANDLER2: root ERROR: Hello Alice;
113 LOG-HANDLER2: root WARNING: Hello Bob;
114 """