Skip to content

Commit dbd48d6

Browse files
committed
Log messages both to sys.stdout and sys.__stdout__ if they differ. This way we get stopping messages to real stdout also when using Stop Remote Server keyword.
1 parent db49c69 commit dbd48d6

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

atest/tests/resource.robot

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,7 @@ Stop Remote Library
4242

4343
Server Should Be Stopped And Correct Messages Logged
4444
${result} = Wait For Process timeout=10s on_timeout=terminate
45-
Should Be Equal ${result.stdout}
46-
... Robot Framework remote server starting at 127.0.0.1:${ACTIVE PORT}.
45+
${expected} = Catenate SEPARATOR=\n
46+
... Robot Framework remote server at 127.0.0.1:${ACTIVE PORT} starting.
47+
... Robot Framework remote server at 127.0.0.1:${ACTIVE PORT} stopping.
48+
Should Be Equal ${result.stdout} ${expected}

src/robotremoteserver.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def stop_with_signal(signum, frame):
6969

7070
def _announce_start(self, port_file=None):
7171
host, port = self.server_address
72-
self._log('Robot Framework remote server starting at %s:%s.'
72+
self._log('Robot Framework remote server at %s:%s starting.'
7373
% (host, port))
7474
if port_file:
7575
pf = open(port_file, 'w')
@@ -252,5 +252,10 @@ def _restore_std_streams(self):
252252
def _log(self, msg, level=None):
253253
if level:
254254
msg = '*%s* %s' % (level.upper(), msg)
255-
sys.stdout.write(msg + '\n')
256-
sys.stdout.flush()
255+
self._write_to_stream(msg, sys.stdout)
256+
if sys.__stdout__ is not sys.stdout:
257+
self._write_to_stream(msg, sys.__stdout__)
258+
259+
def _write_to_stream(self, msg, stream):
260+
stream.write(msg + '\n')
261+
stream.flush()

0 commit comments

Comments
 (0)