summaryrefslogtreecommitdiffstats
path: root/Lib/test/libregrtest/runtest.py
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2021-10-13 15:35:21 (GMT)
committerGitHub <noreply@github.com>2021-10-13 15:35:21 (GMT)
commit676201a59f90caace606d11d4172aa74c1cd4992 (patch)
tree50cafc224f0bebf5ecb386caea9fd518aca5b4d0 /Lib/test/libregrtest/runtest.py
parent713bb19356bce9b8f2b95461834fe1dae505f889 (diff)
downloadcpython-676201a59f90caace606d11d4172aa74c1cd4992.zip
cpython-676201a59f90caace606d11d4172aa74c1cd4992.tar.gz
cpython-676201a59f90caace606d11d4172aa74c1cd4992.tar.bz2
bpo-45410: regrtest replaces print_warning.orig_stderr (GH-28926)
When running Python tests with -W, runtest() now replaces support.print_warning.orig_stderr to preserve the messages order. Add an unit test.
Diffstat (limited to 'Lib/test/libregrtest/runtest.py')
-rw-r--r--Lib/test/libregrtest/runtest.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/Lib/test/libregrtest/runtest.py b/Lib/test/libregrtest/runtest.py
index 6fb996a..2397041 100644
--- a/Lib/test/libregrtest/runtest.py
+++ b/Lib/test/libregrtest/runtest.py
@@ -196,10 +196,18 @@ def _runtest(ns: Namespace, test_name: str) -> TestResult:
stream = io.StringIO()
orig_stdout = sys.stdout
orig_stderr = sys.stderr
+ print_warning = support.print_warning
+ orig_print_warnings_stderr = print_warning.orig_stderr
+
output = None
try:
sys.stdout = stream
sys.stderr = stream
+ # print_warning() writes into the temporary stream to preserve
+ # messages order. If support.environment_altered becomes true,
+ # warnings will be written to sys.stderr below.
+ print_warning.orig_stderr = stream
+
result = _runtest_inner(ns, test_name,
display_failure=False)
if not isinstance(result, Passed):
@@ -207,6 +215,7 @@ def _runtest(ns: Namespace, test_name: str) -> TestResult:
finally:
sys.stdout = orig_stdout
sys.stderr = orig_stderr
+ print_warning.orig_stderr = orig_print_warnings_stderr
if output is not None:
sys.stderr.write(output)