Hi,

On 01/04/15 21:16, "Guido G√ľnther" <a...@sigxcpu.org> wrote:

>On Thu, Feb 05, 2015 at 05:31:32PM +0200, Markus Lehtonen wrote:
>> Pipe stdout of the (child) command to sys.stdout of the caller. This
>> makes Python nose to correctly capture the output of the child command,
>> too, which in turn suppresses a lot of spurious output when running
>> nosetests.
>
>We can capture stdout/stderr using a context manager like in
>testutils/capture.py. I'd rather not use a doctest if we need these kind
>of things for that case only.

This patch is intended for suppressing the massive amount of output
generated by buildpackage-rpm unit tests (originating from rpmbuild). The
thing is that testutils.capture does not work here (without this patch) as
the "spurious" output comes from another process. With this patch the
output from the other process can be piped to the main stdout and thus be
captured. On a sidenote, it's about all tests, not just doctests.

Any other ideas how to handle this? Or just ignore the flood of output
(which I don't like, either).


Thanks,
   Markus




>>Signed-off-by: Markus Lehtonen <markus.lehto...@linux.intel.com>
>> ---
>>  gbp/command_wrappers.py | 16 +++++++++++++++-
>>  1 file changed, 15 insertions(+), 1 deletion(-)
>> 
>> diff --git a/gbp/command_wrappers.py b/gbp/command_wrappers.py
>> index f8c50f1..074d30a 100644
>> --- a/gbp/command_wrappers.py
>> +++ b/gbp/command_wrappers.py
>> @@ -23,6 +23,9 @@ import subprocess
>>  import os
>>  import os.path
>>  import signal
>> +import sys
>> +import tempfile
>> +
>>  import gbp.log as log
>>  
>>  class CommandExecFailed(Exception):
>> @@ -67,7 +70,14 @@ class Command(object):
>>  
>>          log.debug("%s %s %s" % (self.cmd, self.args, args))
>>          self._reset_state()
>> -        stdout_arg = subprocess.PIPE if self.capture_stdout else None
>> +        if self.capture_stdout:
>> +            stdout_arg = subprocess.PIPE
>> +        else:
>> +            # Pipe stdout of the child command to sys.stdout so that
>>std*
>> +            # capture in nosetests catches the output of the command,
>>too. We
>> +            # need to use a temporary file if sys.stdout is not a real
>>file.
>> +            stdout_arg = sys.stdout if hasattr(sys.stdout, 'fileno')
>>else \
>> +                                       tempfile.TemporaryFile()
>>          stderr_arg = subprocess.PIPE if self.capture_stderr else \
>>                                          subprocess.STDOUT
>>          cmd = [ self.cmd ] + self.args + args
>> @@ -84,6 +94,10 @@ class Command(object):
>>                                       stdout=stdout_arg,
>>                                       stderr=stderr_arg)
>>              (self.stdout, self.stderr) = popen.communicate()
>> +            # Write stdout content back to sys.stdout if the tempfile
>>hack was used
>> +            if stdout_arg not in [sys.stdout, subprocess.PIPE]:
>> +                stdout_arg.seek(0)
>> +                sys.stdout.write(stdout_arg.read())
>>          except OSError as err:
>>              self.err_reason = "execution failed: %s" % str(err)
>>              self.retcode = 1
>> -- 
>> 2.1.4


_______________________________________________
git-buildpackage mailing list
git-buildpackage@lists.sigxcpu.org
http://lists.sigxcpu.org/mailman/listinfo/git-buildpackage

Reply via email to