diff --git a/Lib/test/test_generated_cases.py b/Lib/test/test_generated_cases.py index ed56f95af99..be3dfd204ee 100644 --- a/Lib/test/test_generated_cases.py +++ b/Lib/test/test_generated_cases.py @@ -1,7 +1,9 @@ +import contextlib import tempfile import unittest import os +from test import support from test import test_tools test_tools.skip_if_missing('cases_generator') @@ -12,6 +14,12 @@ with test_tools.imports_under_tool('cases_generator'): from parsing import StackEffect +def handle_stderr(): + if support.verbose > 1: + return contextlib.nullcontext() + else: + return support.captured_stderr() + class TestEffects(unittest.TestCase): def test_effect_sizes(self): input_effects = [ @@ -81,11 +89,12 @@ class TestGeneratedCases(unittest.TestCase): temp_input.flush() a = generate_cases.Generator([self.temp_input_filename]) - a.parse() - a.analyze() - if a.errors: - raise RuntimeError(f"Found {a.errors} errors") - a.write_instructions(self.temp_output_filename, False) + with handle_stderr(): + a.parse() + a.analyze() + if a.errors: + raise RuntimeError(f"Found {a.errors} errors") + a.write_instructions(self.temp_output_filename, False) with open(self.temp_output_filename) as temp_output: lines = temp_output.readlines()