]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.11] [3.12] gh-117347: Fix test_clinic side effects (GH-117363) (GH-117365) (#117366)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 29 Mar 2024 11:21:56 +0000 (12:21 +0100)
committerGitHub <noreply@github.com>
Fri, 29 Mar 2024 11:21:56 +0000 (11:21 +0000)
[3.12] gh-117347: Fix test_clinic side effects (GH-117363) (GH-117365)

gh-117347: Fix test_clinic side effects (GH-117363)

Save/restore converters in ClinicWholeFileTest and
ClinicExternalTest.

(cherry picked from commit c80d13838dbcfe239eeabfd950bc524d797e6db1)

Co-authored-by: Victor Stinner <vstinner@python.org>
(cherry picked from commit 35b6c4a4da201a947b2ceb96ae4c0d83d4d2df4f)

Co-authored-by: Victor Stinner <vstinner@python.org>
Lib/test/test_clinic.py

index 748a63e5348fce1d114bda48f29cae16390ea504..902d43cb1d67dffa58623053318096a2a81dc029 100644 (file)
@@ -22,6 +22,20 @@ with test_tools.imports_under_tool('clinic'):
     from clinic import DSLParser
 
 
+def restore_dict(converters, old_converters):
+    converters.clear()
+    converters.update(old_converters)
+
+
+def save_restore_converters(testcase):
+    testcase.addCleanup(restore_dict, clinic.converters,
+                        clinic.converters.copy())
+    testcase.addCleanup(restore_dict, clinic.legacy_converters,
+                        clinic.legacy_converters.copy())
+    testcase.addCleanup(restore_dict, clinic.return_converters,
+                        clinic.return_converters.copy())
+
+
 class _ParserBase(TestCase):
     maxDiff = None
 
@@ -108,6 +122,7 @@ class FakeClinic:
 
 class ClinicWholeFileTest(_ParserBase):
     def setUp(self):
+        save_restore_converters(self)
         self.clinic = clinic.Clinic(clinic.CLanguage(None), filename="test.c")
 
     def expect_failure(self, raw):
@@ -1317,6 +1332,9 @@ class ClinicExternalTest(TestCase):
     maxDiff = None
     clinic_py = os.path.join(test_tools.toolsdir, "clinic", "clinic.py")
 
+    def setUp(self):
+        save_restore_converters(self)
+
     def _do_test(self, *args, expect_success=True):
         with subprocess.Popen(
             [sys.executable, "-Xutf8", self.clinic_py, *args],