8000 Fix logging when keyword uses BuiltIn.run_keyword internally. · pythonthings/robotframework@2783f85 · GitHub
[go: up one dir, main page]

Skip to content < 8000 span style="width: 0%;" data-view-component="true" class="Progress-item progress-pjax-loader-bar left-0 top-0 color-bg-accent-emphasis">

Commit 2783f85

Browse files
committed
Fix logging when keyword uses BuiltIn.run_keyword internally.
Regression was caused by a fix for intermittent corrupted outputs when logging during timeuts (robotframework#2839). The fix for the regression basically removes the earlier fix when BuiltIn.run_keyword is used internally by a keyword. Luckily there shouldn't be too many use cases for that.
1 parent b1dc83e commit 2783f85

File tree

4 files changed

+25
-6
lines changed

4 files changed

+25
-6
lines changed

atest/robot/standard_libraries/builtin/used_in_custom_libs_and_listeners.robot

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,13 @@ Use 'Run Keyword' with non-Unicode values
1818
${tc} = Check Test Case ${TESTNAME}
1919
Check Log Message ${tc.kws[0].kws[0].msgs[0]} 42
2020
Check Log Message ${tc.kws[0].kws[1].msgs[0]} \\xff
21+
22+
Use BuiltIn keywords with timeouts
23+
${tc} = Check Test Case ${TESTNAME}
24+
Check Log Message ${tc.kws[0].msgs[0]} Test timeout 1 day active. * seconds left. level=DEBUG pattern=True
25+
Check Log Message ${tc.kws[0].msgs[1]} Log level changed from INFO to DEBUG.
26+
Check Log Message ${tc.kws[0].msgs[2]} Hello, debug world! DEBUG
27+
Check Log Message ${tc.kws[3].kws[0].msgs[0]} Test timeout 1 day active. * seconds left. level=DEBUG pattern=True
28+
Check Log Message ${tc.kws[3].kws[0].msgs[1]} 42
29+
Check Log Message ${tc.kws[3].kws[1].msgs[0]} Test timeout 1 day active. * seconds left. level=DEBUG pattern=True
30+
Check Log Message ${tc.kws[3].kws[1].msgs[1]} \\xff

atest/testdata/standard_libraries/builtin/used_in_custom_libs_and_listeners.robot

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
*** Settings ***
22
Library UseBuiltIn.py
3+
Test Setup Set Log Level INFO
34

45
*** Test Cases ***
56
Keywords Using BuiltIn
@@ -15,3 +16,10 @@ Listener Using BuiltIn
1516

1617
Use 'Run Keyword' with non-Unicode values
1718
Use Run Keyword with non Unicode values
19+
20+
Use BuiltIn keywords with timeouts
21+
[Timeout] 1 day
22+
Log Debug Message
23+
Set Secret Variable
24+
Should Be Equal ${secret} *****
25+
Use Run Keyword with non Unicode values

src/robot/output/logger.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,18 +162,19 @@ def cache_only(self):
162162
@property
163163
@contextmanager
164164
def delayed_logging(self):
165+
prev_cache = self._log_message_cache
165166
self._log_message_cache = []
166167
try:
167168
yield
168169
finally:
169170
messages = self._log_message_cache
170-
self._log_message_cache = None
171-
for msg in messages:
172-
self.log_message(msg)
171+
self._log_message_cache = prev_cache
172+
for msg in messages or ():
173+
self._log_message(msg, no_cache=True)
173174

174-
def _log_message(self, msg):
175+
def _log_message(self, msg, no_cache=False):
175176
"""Log messages written (mainly) by libraries."""
176-
if self._log_message_cache is not None:
177+
if self._log_message_cache is not None and not no_cache:
177178
self._log_message_cache.append(msg)
178179
return
179180
for logger in self:

src/robot/running/librarykeywordrunner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ def _trace_log_args(self, positional, named):
8585
def _runner_for(self, context, handler, positional, named):
8686
timeout = self._get_timeout(context)
8787
if timeout and timeout.active:
88-
context.output.debug(timeout.get_message)
8988
def runner():
9089
with LOGGER.delayed_logging:
90+
context.output.debug(timeout.get_message())
9191
return timeout.run(handler, args=positional, kwargs=named)
9292
return runner
9393
return lambda: handler(*positional, **named)

0 commit comments

Comments
 (0)
0