[Pytest-commit] commit/tox: hpk42: Merged in fschulze/tox/echo-captured-output (pull request #132)

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Mon Feb 9 12:13:59 CET 2015


1 new commit in tox:

https://bitbucket.org/hpk42/tox/commits/27b8bdcddd6a/
Changeset:   27b8bdcddd6a
User:        hpk42
Date:        2015-02-09 11:13:56+00:00
Summary:     Merged in fschulze/tox/echo-captured-output (pull request #132)

Add ``--result-tee`` option to echo output captured for the json result to stdout.
Affected #:  3 files

diff -r 50f3b98fc65b951ab07e6b5e3fbd5a2fc9c48f2c -r 27b8bdcddd6a197ad600afac03a1e3fb61cc6a5b CHANGELOG
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -10,6 +10,7 @@
 
 - refine determination if we run from Jenkins, thanks Borge Lanes.
 
+- echo output to stdout when ``--report-json`` is used
 
 1.8.1
 -----------

diff -r 50f3b98fc65b951ab07e6b5e3fbd5a2fc9c48f2c -r 27b8bdcddd6a197ad600afac03a1e3fb61cc6a5b tox/_cmdline.py
--- a/tox/_cmdline.py
+++ b/tox/_cmdline.py
@@ -11,6 +11,7 @@
 import os
 import sys
 import subprocess
+import time
 from tox._verlib import NormalizedVersion, IrrationalVersionError
 from tox._venv import VirtualEnv
 from tox._config import parseconfig
@@ -79,7 +80,7 @@
         return f
 
     def popen(self, args, cwd=None, env=None, redirect=True, returnout=False):
-        f = outpath = None
+        stdout = outpath = None
         resultjson = self.session.config.option.resultjson
         if resultjson or redirect:
             f = self._initlogpath(self.id)
@@ -87,14 +88,18 @@
                     self.id, self.msg, args, env))
             f.flush()
             self.popen_outpath = outpath = py.path.local(f.name)
+            if resultjson:
+                stdout = subprocess.PIPE
+            else:
+                stdout = f
         elif returnout:
-            f = subprocess.PIPE
+            stdout = subprocess.PIPE
         if cwd is None:
             # XXX cwd = self.session.config.cwd
             cwd = py.path.local()
         try:
             popen = self._popen(args, cwd, env=env,
-                                stdout=f, stderr=STDOUT)
+                                stdout=stdout, stderr=STDOUT)
         except OSError as e:
             self.report.error("invocation failed (errno %d), args: %s, cwd: %s" %
                               (e.errno, args, cwd))
@@ -107,7 +112,28 @@
         try:
             self.report.logpopen(popen, env=env)
             try:
-                out, err = popen.communicate()
+                if resultjson and not redirect:
+                    assert popen.stderr is None  # prevent deadlock
+                    out = None
+                    last_time = time.time()
+                    while 1:
+                        # we have to read one byte at a time, otherwise there
+                        # might be no output for a long time with slow tests
+                        data = popen.stdout.read(1)
+                        if data:
+                            sys.stdout.write(data)
+                            if '\n' in data or (time.time() - last_time) > 5:
+                                # we flush on newlines or after 5 seconds to
+                                # provide quick enough feedback to the user
+                                # when printing a dot per test
+                                sys.stdout.flush()
+                                last_time = time.time()
+                            f.write(data)
+                        elif popen.poll() is not None:
+                            popen.stdout.close()
+                            break
+                else:
+                    out, err = popen.communicate()
             except KeyboardInterrupt:
                 self.report.keyboard_interrupt()
                 popen.wait()

Repository URL: https://bitbucket.org/hpk42/tox/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.


More information about the pytest-commit mailing list