Skip to content

Commit

Permalink
Redirect luatest stderr to stdout with new option
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Oleg Chaplashkin committed Sep 18, 2023
1 parent 8ebb3aa commit 16c2ad2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
5 changes: 4 additions & 1 deletion lib/luatest_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
22 changes: 21 additions & 1 deletion lib/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ 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"""

Expand Down Expand Up @@ -126,7 +134,7 @@ def __init__(self):
parser.add_argument(
"--verbose",
dest='is_verbose',
action="store_true",
action=DeprecationWarning,
default=False,
help=format_help(
"""
Expand All @@ -135,6 +143,18 @@ def __init__(self):
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',
Expand Down
2 changes: 1 addition & 1 deletion lib/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 16c2ad2

Please sign in to comment.