summaryrefslogtreecommitdiffstats
path: root/Lib/test/support
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2021-10-11 21:07:21 (GMT)
committerGitHub <noreply@github.com>2021-10-11 21:07:21 (GMT)
commit1ebd798fddef51e1f6fd40a4860278a1851ac268 (patch)
treeac15076d8bd096d265072c9888361640400a8eee /Lib/test/support
parent47717d1186563695e798b40350d15b00d04a5237 (diff)
downloadcpython-1ebd798fddef51e1f6fd40a4860278a1851ac268.zip
cpython-1ebd798fddef51e1f6fd40a4860278a1851ac268.tar.gz
cpython-1ebd798fddef51e1f6fd40a4860278a1851ac268.tar.bz2
bpo-45410: Add test.support.flush_std_streams() (GH-28885)
support.print_warning() now flushs sys.stdout.
Diffstat (limited to 'Lib/test/support')
-rw-r--r--Lib/test/support/__init__.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
index b29f438..0bbe813 100644
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -1167,7 +1167,16 @@ def run_doctest(module, verbosity=None, optionflags=0):
#=======================================================================
# Support for saving and restoring the imported modules.
+def flush_std_streams():
+ if sys.stdout is not None:
+ sys.stdout.flush()
+ if sys.stderr is not None:
+ sys.stderr.flush()
+
+
def print_warning(msg):
+ # bpo-45410: Explicitly flush stdout to keep logs in order
+ flush_std_streams()
# bpo-39983: Print into sys.__stderr__ to display the warning even
# when sys.stderr is captured temporarily by a test
for line in msg.splitlines():