Skip to content

Commit 556e2d6

Browse files
committed
Fix #426 by writing directly to stdout buffer if possible to prevent str vs bytes issues.
1 parent 659fd14 commit 556e2d6

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

changelog/426.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Write directly to stdout buffer if possible to prevent str vs bytes issues - by @asottile

tox/session.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,19 +160,22 @@ def popen(self, args, cwd=None, env=None, redirect=True, returnout=False, ignore
160160
try:
161161
if resultjson and not redirect:
162162
assert popen.stderr is None # prevent deadlock
163+
# we read binary from the process and must write using a
164+
# binary stream
165+
buf = getattr(sys.stdout, 'buffer', sys.stdout)
163166
out = None
164167
last_time = time.time()
165168
while 1:
166169
# we have to read one byte at a time, otherwise there
167170
# might be no output for a long time with slow tests
168171
data = fin.read(1)
169172
if data:
170-
sys.stdout.write(data)
173+
buf.write(data)
171174
if b'\n' in data or (time.time() - last_time) > 1:
172175
# we flush on newlines or after 1 second to
173176
# provide quick enough feedback to the user
174177
# when printing a dot per test
175-
sys.stdout.flush()
178+
buf.flush()
176179
last_time = time.time()
177180
elif popen.poll() is not None:
178181
if popen.stdout is not None:

0 commit comments

Comments
 (0)