Patchwork [5,of,6] py3: flush std streams before/after running user code in heredoctest.py

login
register
mail settings
Submitter Yuya Nishihara
Date Oct. 16, 2018, 7:26 a.m.
Message ID <8190570be13dc584dfab.1539674804@mimosa>
Download mbox | patch
Permalink /patch/36029/
State Accepted
Headers show

Comments

Yuya Nishihara - Oct. 16, 2018, 7:26 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1539667110 -7200
#      Tue Oct 16 07:18:30 2018 +0200
# Node ID 8190570be13dc584dfab6b8470546c298d6900b6
# Parent  a202f1b4611205a08a6730db63dfead59b69f42b
py3: flush std streams before/after running user code in heredoctest.py

Otherwise, things written to stdout.buffer would be interleaved.

Patch

diff --git a/tests/heredoctest.py b/tests/heredoctest.py
--- a/tests/heredoctest.py
+++ b/tests/heredoctest.py
@@ -2,6 +2,10 @@  from __future__ import absolute_import, 
 
 import sys
 
+def flush():
+    sys.stdout.flush()
+    sys.stderr.flush()
+
 globalvars = {}
 lines = sys.stdin.readlines()
 while lines:
@@ -15,6 +19,9 @@  while lines:
             snippet += l[4:]
         c = compile(snippet, '<heredoc>', 'single')
         try:
+            flush()
             exec(c, globalvars)
+            flush()
         except Exception as inst:
+            flush()
             print(repr(inst))