diff --git a/tests/heredoctest.py b/tests/heredoctest.py
index 6958eb9bdcd6cb90639880ae6274ac5353031e79_dGVzdHMvaGVyZWRvY3Rlc3QucHk=..55fd0fefbec499b52b311cce77c9588a4b169ef8_dGVzdHMvaGVyZWRvY3Rlc3QucHk= 100644
--- a/tests/heredoctest.py
+++ b/tests/heredoctest.py
@@ -2,6 +2,10 @@
 
 import sys
 
+def flush():
+    sys.stdout.flush()
+    sys.stderr.flush()
+
 globalvars = {}
 lines = sys.stdin.readlines()
 while lines:
@@ -15,4 +19,5 @@
             snippet += l[4:]
         c = compile(snippet, '<heredoc>', 'single')
         try:
+            flush()
             exec(c, globalvars)
@@ -18,2 +23,3 @@
             exec(c, globalvars)
+            flush()
         except Exception as inst:
@@ -19,2 +25,3 @@
         except Exception as inst:
+            flush()
             print(repr(inst))