]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-103186: Make test_generated_cases less noisy by default (GH-109100)
authorSerhiy Storchaka <storchaka@gmail.com>
Thu, 7 Sep 2023 17:53:38 +0000 (20:53 +0300)
committerGitHub <noreply@github.com>
Thu, 7 Sep 2023 17:53:38 +0000 (20:53 +0300)
Print additional details only when tests are run with -vv.

Lib/test/test_generated_cases.py

index ed56f95af99417b38028c447a31d03be631812c3..be3dfd204ee143355baa9329e313daa795051a83 100644 (file)
@@ -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()