From d108b71833c00d30b2b575371511c85f4941f1b9 Mon Sep 17 00:00:00 2001 From: Oleg Chaplashkin Date: Mon, 18 Sep 2023 17:35:49 +0400 Subject: [PATCH] Redirect luatest stderr to stdout with new option By default, test-run captures the stderr stream and redirects its to the log file: $ cat /tmp/t/001_foo-luatest/foo_test.log: [001] Some error log [001] My warning log ... Use the new option `--show-capture` (abbr. `-c`) to redirect stderr to stdout. Use it instead of the deprecated `--verbose` option. The `--verbose` option will be ignored and output: Argument ['--verbose'] is deprecated and is ignored. Close tarantool/luatest#308 --- lib/luatest_server.py | 5 ++++- lib/options.py | 26 +++++++++++++++++++++++++- lib/test.py | 2 +- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/lib/luatest_server.py b/lib/luatest_server.py index 0793601d..ac68e2f5 100644 --- a/lib/luatest_server.py +++ b/lib/luatest_server.py @@ -62,7 +62,10 @@ def execute(self, server): project_dir = os.environ['SOURCEDIR'] with open(server.logfile, 'ab') as f: - proc = Popen(command, cwd=project_dir, stdout=sys.stdout, stderr=f) + stderr = f + if Options().args.show_capture: + stderr = sys.stdout + proc = Popen(command, cwd=project_dir, stdout=sys.stdout, stderr=stderr) sampler.register_process(proc.pid, self.id, server.name) test_timeout = Options().args.test_timeout timer = Timer(test_timeout, timeout_handler, (proc, test_timeout)) diff --git a/lib/options.py b/lib/options.py index 12021b35..88c95051 100644 --- a/lib/options.py +++ b/lib/options.py @@ -37,6 +37,17 @@ def format_help(s): return textwrap.dedent(s.lstrip('\n')) + '\n' +class DeprecationWarning(argparse._StoreTrueAction): + """Сustom definition of the 'store_true' procedure""" + + def __call__(self, parser, namespace, values, option_string=None): + color_stdout( + "Argument %s is deprecated and is ignored.\n" % self.option_strings, + schema='info' + ) + setattr(namespace, self.dest, values) + + class Options(object): """Handle options of test-runner""" @@ -126,15 +137,28 @@ def __init__(self): parser.add_argument( "--verbose", dest='is_verbose', - action="store_true", + action=DeprecationWarning, default=False, help=format_help( """ + Deprecated. Print TAP13 test output to log. Default: false. """)) + parser.add_argument( + "-c", "--show-capture", + dest='show_capture', + action='store_true', + default=False, + help=format_help( + """ + Whether to show captured TAP13 output or not. + + Default: false. + """)) + parser.add_argument( '--debug', dest='debug', diff --git a/lib/test.py b/lib/test.py index d3585ed1..248ff79c 100644 --- a/lib/test.py +++ b/lib/test.py @@ -226,7 +226,7 @@ def run(self, server): self.is_equal_result = filecmp.cmp(self.result, self.tmp_result) elif self.is_executed_ok: - if Options().args.is_verbose: + if Options().args.show_capture: color_stdout('\n') with open(self.tmp_result, 'r') as f: color_stdout(f.read(), schema='log')