want to get stdout and stderr back

304 views
Skip to first unread message

Law R

unread,
May 6, 2021, 9:12:20 AM5/6/21
to robotframework-users
Hello,
I am a newbie to robot framework. During python library development, I want to use python console to try code. Since RF owns the stdout/stderr, I have to use logger api to write variable to console. Is it possible to turn off RF console so python console can own stdout? I tried looking up RF source code but couldn't find any flag.

Thank you
Lawrence

Pekka Klärck

unread,
May 6, 2021, 9:32:03 AM5/6/21
to lazh...@gmail.com, robotframework-users
Hi,

there's no direct way to change `print()` using in RF keyword to write
to the console instead of the log file, but there are few things you
can do:

1. Use `robot.api.logger.console('Message')` as you apparently already
have done.

2. Use `print('Message', file=sys.__stdout__)`. RF intercepts
`sys.stdout` but leaves `sys.__stdout__` alone (as all well behaving
programs should).

3. Create a helper logger function that you can configure to log to
the console when needed. The helper could use either of the above
ways.

Cheers,
.peke
> --
> You received this message because you are subscribed to the Google Groups "robotframework-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-u...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/robotframework-users/4d1ba6bd-eec9-4cf5-ad1b-2ca10d65c0a2n%40googlegroups.com.



--
Agile Tester/Developer/Consultant :: http://eliga.fi
Lead Developer of Robot Framework :: http://robotframework.org

Law R

unread,
May 7, 2021, 2:55:41 AM5/7/21
to Pekka Klärck, robotframework-users
Hi Pekka,

Thank you for taking the time to reply.

Yes, I can use logger API to print simple variables. There are times when I want to use pprint. Or I write python code hoping the console points out syntax errors. That's the fun of python interactive programming. Currently the console doesn't output anything when I make syntax mistake.

If possible, I want to completely disable RF logger so python console owns stdout and stderr.

Cheers
Lawrence
Reply all
Reply to author
Forward
0 new messages