提交 9997aaa1 编写于 作者: C Cleber Rosa

Output check: allow for an explicit `none` mode

In commit 4514a8ad, the default value from the command line option
`--output-check-record` was being used to set the mode of the
`avocado.utils.process` APIs with regards to output record mode.

The problem with that is it makes it impossible for the API to
distinguish between "no explicit behavior requested" and "explicitly
being asked to disable recording".
Signed-off-by: NCleber Rosa <crosa@redhat.com>
上级 4d1b5ea0
......@@ -136,13 +136,11 @@ class Run(CLICmd):
out_check.add_argument('--output-check-record',
choices=('none', 'all', 'stdout', 'stderr',
'both', 'combined'),
default='none',
help="Record output streams of your tests "
"to reference files (valid options: none (do "
"not record output streams), all (record both "
"stdout and stderr), stdout (record only "
"stderr), stderr (record only stderr). "
'Current: %(default)s')
"stderr), stderr (record only stderr). ")
out_check.add_argument('--output-check', choices=('on', 'off'),
default='on',
......@@ -174,7 +172,9 @@ class Run(CLICmd):
:param args: Command line args received from the run subparser.
"""
if 'output_check_record' in args:
process.OUTPUT_CHECK_RECORD_MODE = getattr(args, 'output_check_record')
process.OUTPUT_CHECK_RECORD_MODE = getattr(args,
'output_check_record',
None)
if args.unique_job_id is not None:
try:
......
......@@ -413,11 +413,17 @@ class SubProcess(object):
'stdout', for standard output *only*,
'stderr' for standard error *only*,
'both' for both standard output and error
in separate files (default), 'combined' for
in separate files, 'combined' for
standard output and error in a single file,
and 'none' to disable all recording. 'all'
is also a valid, but deprecated, option that
is a synonym of 'both'.
is a synonym of 'both'. If an explicit value
is not given to this parameter, that is, if
None is given, it defaults to using the module
level configuration, as set by
:data:`OUTPUT_CHECK_RECORD_MODE`. If the
module level configuration itself is not set,
it defaults to 'none'.
:type allow_output_check: str
:param shell: Whether to run the subprocess in a subshell.
:type shell: bool
......@@ -542,13 +548,19 @@ class SubProcess(object):
self._combined_drainer.start()
else:
if self.allow_output_check == 'none':
stdout_stream_logger = None
stderr_stream_logger = None
else:
stdout_stream_logger = stdout_log
stderr_stream_logger = stderr_log
self._stdout_drainer = FDDrainer(
self._popen.stdout.fileno(),
self.result,
name="%s-stdout" % self.cmd,
logger=log,
logger_prefix="[stdout] %s",
stream_logger=stdout_log,
stream_logger=stdout_stream_logger,
ignore_bg_processes=self._ignore_bg_processes,
verbose=self.verbose)
self._stderr_drainer = FDDrainer(
......@@ -557,7 +569,7 @@ class SubProcess(object):
name="%s-stderr" % self.cmd,
logger=log,
logger_prefix="[stderr] %s",
stream_logger=stderr_log,
stream_logger=stderr_stream_logger,
ignore_bg_processes=self._ignore_bg_processes,
verbose=self.verbose)
......
......@@ -71,6 +71,21 @@ class OutputTest(Test):
process.run("/bin/echo -n del_process")
"""
OUTPUT_MODE_NONE_CONTENT = r"""
import sys
from avocado import Test
from avocado.utils import process
class OutputCheckNone(Test):
def test(self):
cmd = "%s -c \"import sys; sys.%%s.write('%%s')\"" % sys.executable
process.run(cmd % ('stdout', '__STDOUT_DONT_RECORD_CONTENT__'))
process.run(cmd % ('stderr', '__STDERR_DONT_RECORD_CONTENT__'))
"""
def image_output_uncapable():
try:
......@@ -169,6 +184,35 @@ class OutputTest(unittest.TestCase):
self.assertEqual("test_process__test_stderr____test_stdout__",
open(os.path.join(testdir, "output")).read())
def test_check_record_no_module_default(self):
"""
Checks that the `avocado.utils.process` module won't have a output
check record mode (`OUTPUT_CHECK_RECORD_MODE`) set by default.
The reason is that, if this is always set from the command
line runner, we can't distinguish from a situation where the
module level configuration should be applied as a fallback to
the API parameter. By leaving it unset by default, the command line
option parameter value `none` will slightly change its behavior,
meaning that it will explicitly disable output check record when
asked to do so.
"""
with script.Script(os.path.join(self.tmpdir, "output_mode_none.py"),
OUTPUT_MODE_NONE_CONTENT,
script.READ_ONLY_MODE) as test:
cmd = ("%s run --job-results-dir %s --sysinfo=off "
"--json - --output-check-record none -- %s") % (AVOCADO,
self.tmpdir,
test.path)
result = process.run(cmd)
res = json.loads(result.stdout)
testdir = res["tests"][0]["logdir"]
for output_file in ('stdout', 'stderr', 'output'):
output_file_path = os.path.join(testdir, output_file)
self.assertTrue(os.path.exists(output_file_path))
with open(output_file_path, 'r') as output:
self.assertEqual(output.read(), '')
def tearDown(self):
shutil.rmtree(self.tmpdir)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册