diff --git a/lib/luatest_server.py b/lib/luatest_server.py index ac68e2f5..0a19fb11 100644 --- a/lib/luatest_server.py +++ b/lib/luatest_server.py @@ -14,6 +14,7 @@ from lib.tarantool_server import Test from lib.tarantool_server import TestExecutionError from lib.tarantool_server import TarantoolServer +from lib.utils import captured_stderr def timeout_handler(process, test_timeout): @@ -62,10 +63,8 @@ def execute(self, server): project_dir = os.environ['SOURCEDIR'] with open(server.logfile, 'ab') as f: - stderr = f - if Options().args.show_capture: - stderr = sys.stdout - proc = Popen(command, cwd=project_dir, stdout=sys.stdout, stderr=stderr) + with captured_stderr(f): + proc = Popen(command, cwd=project_dir, stdout=sys.stdout, stderr=f) 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 88c95051..c9cb0fb5 100644 --- a/lib/options.py +++ b/lib/options.py @@ -37,17 +37,6 @@ 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""" @@ -135,13 +124,12 @@ def __init__(self): """)) parser.add_argument( - "--verbose", + "-v", "--verbose", dest='is_verbose', - action=DeprecationWarning, + action='store_true', default=False, help=format_help( """ - Deprecated. Print TAP13 test output to log. Default: false. diff --git a/lib/test.py b/lib/test.py index 248ff79c..d3585ed1 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.show_capture: + if Options().args.is_verbose: color_stdout('\n') with open(self.tmp_result, 'r') as f: color_stdout(f.read(), schema='log') diff --git a/lib/utils.py b/lib/utils.py index 03423768..9a79cca9 100644 --- a/lib/utils.py +++ b/lib/utils.py @@ -372,3 +372,23 @@ def prepend_path(p): def shlex_quote(s): return _shlex_quote(s) + + +class captured_stderr: + def __init__(self, logfile): + self.prevfd = None + self.prev = None + self.f = logfile + + def __enter__(self): + self.prevfde = os.dup(self.f.fileno()) + + os.dup2(sys.stderr.fileno(), self.f.fileno()) + + self.preve = sys.stderr + sys.stderr = os.fdopen(self.prevfde, "w") + return self.f + + def __exit__(self, exc_type, exc_value, traceback): + os.dup2(self.prevfde, self.preve.fileno()) + sys.stderr = self.preve