do not redirect_stdout in test scripts
In a test, I called print() on a multi-line string and saw the log
showing each line 0.2 seconds apart. redirect.stdout seems to be pretty
inefficient.
Instead, put a print() function into the testenv, to directly call log()
on the strings passed to print().
The initial idea for redirect_stdout was that we could print() in any
deeper functions called from a test script. But we have no such nested
print() anywhere, only in test scripts themselves.
As a result of this, a multi-line print() in test scripts now no longer
puts the log prefix (timestamp, test name...) and suffix (backtrace /
source position) to each single line, but prints the multiline block
between a single log prefix and suffix -- exactly like the log()
function does everywhere else.
I actually briefly implemented adding the log prefix to each separate
line everywhere, but decided that it is not a good idea: in some places
we log config file snippets and other lists, and prepending the log
prefix to each line makes pasting such a snippet from (say) a jenkins
log super cumbersome. And the log prefix (backtrace) attached on each
separate line makes multiline blocks very noisy, unreadable.
Change-Id: I0972c66b9165bd7f2b0b387e0335172849199193
diff --git a/src/osmo_gsm_tester/testenv.py b/src/osmo_gsm_tester/testenv.py
index ebc8f91..b3db84f 100644
--- a/src/osmo_gsm_tester/testenv.py
+++ b/src/osmo_gsm_tester/testenv.py
@@ -43,6 +43,7 @@
Sms = None
process = None
tenv = None
+print = None
class Timeout(Exception):
pass
@@ -351,12 +352,15 @@
self.log('using BVCI', bvci)
return bvci
+ def print(self, *messages, **named_items):
+ log_module.log(*messages, _origin=self.test(), _src=3, **named_items)
+
def setup(suite_run, _test):
from .core.event_loop import MainLoop
from .obj.sms import Sms as Sms_class
- global test, log, dbg, err, wait, wait_no_raise, sleep, poll, prompt, Sms, process, tenv
+ global test, log, dbg, err, wait, wait_no_raise, sleep, poll, prompt, Sms, process, tenv, print
test = _test
log = test.log
@@ -370,6 +374,7 @@
Sms = Sms_class
process = process_module
prompt = tenv.prompt
+ print = tenv.print
return tenv
# vim: expandtab tabstop=4 shiftwidth=4