summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Schulze <mail@florian-schulze.net>2018-01-11 14:26:48 +0100
committerGábor Bernát <jokerjokerer@gmail.com>2018-01-11 13:26:48 +0000
commit51ea3080f0b6d7b13606a4b2ab2379eccfbb75f8 (patch)
treea8bd984a0a2bc81810bccafdb03f8dd9a514a5b8
parent659fd14f12028d2e3dc843dfd4b217a474172728 (diff)
downloadtox-git-51ea3080f0b6d7b13606a4b2ab2379eccfbb75f8.tar.gz
Fix #426 by writing directly to stdout buffer if possible to prevent str vs bytes issues. (#739)
* Fix #426 by writing directly to stdout buffer if possible to prevent str vs bytes issues. * Don't use assert in production code.
-rw-r--r--CONTRIBUTORS1
-rw-r--r--changelog/426.bugfix.rst1
-rw-r--r--tox/session.py11
3 files changed, 10 insertions, 3 deletions
diff --git a/CONTRIBUTORS b/CONTRIBUTORS
index 560161d9..f6ef60be 100644
--- a/CONTRIBUTORS
+++ b/CONTRIBUTORS
@@ -5,6 +5,7 @@ Alexandre Conrad
Allan Feldman
Andrii Soldatenko
Anthon van der Neuth
+Anthony Sottile
Asmund Grammeltwedt
Barry Warsaw
Bartolome Sanchez Salado
diff --git a/changelog/426.bugfix.rst b/changelog/426.bugfix.rst
new file mode 100644
index 00000000..caf55dd2
--- /dev/null
+++ b/changelog/426.bugfix.rst
@@ -0,0 +1 @@
+Write directly to stdout buffer if possible to prevent str vs bytes issues - by @asottile
diff --git a/tox/session.py b/tox/session.py
index a414b4fe..8341d9ad 100644
--- a/tox/session.py
+++ b/tox/session.py
@@ -159,7 +159,12 @@ class Action(object):
self.report.logpopen(popen, env=env)
try:
if resultjson and not redirect:
- assert popen.stderr is None # prevent deadlock
+ if popen.stderr is not None:
+ # prevent deadlock
+ raise ValueError("stderr must not be piped here")
+ # we read binary from the process and must write using a
+ # binary stream
+ buf = getattr(sys.stdout, 'buffer', sys.stdout)
out = None
last_time = time.time()
while 1:
@@ -167,12 +172,12 @@ class Action(object):
# might be no output for a long time with slow tests
data = fin.read(1)
if data:
- sys.stdout.write(data)
+ buf.write(data)
if b'\n' in data or (time.time() - last_time) > 1:
# we flush on newlines or after 1 second to
# provide quick enough feedback to the user
# when printing a dot per test
- sys.stdout.flush()
+ buf.flush()
last_time = time.time()
elif popen.poll() is not None:
if popen.stdout is not None: