https://github.com/python/cpython/commit/35b6c4a4da201a947b2ceb96ae4c0d83d4d2df4f
commit: 35b6c4a4da201a947b2ceb96ae4c0d83d4d2df4f
branch: main
author: Victor Stinner <[email protected]>
committer: vstinner <[email protected]>
date: 2024-03-29T10:25:17Z
summary:

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

Save/restore converters in ClinicWholeFileTest and
ClinicExternalTest.

files:
M Lib/test/test_clinic.py

diff --git a/Lib/test/test_clinic.py b/Lib/test/test_clinic.py
index 52cb4d6e187855..f95bf858100be6 100644
--- a/Lib/test/test_clinic.py
+++ b/Lib/test/test_clinic.py
@@ -52,6 +52,20 @@ def _expect_failure(tc, parser, code, errmsg, *, 
filename=None, lineno=None,
     return cm.exception
 
 
+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 ClinicWholeFileTest(TestCase):
     maxDiff = None
 
@@ -60,6 +74,7 @@ def expect_failure(self, raw, errmsg, *, filename=None, 
lineno=None):
                         filename=filename, lineno=lineno)
 
     def setUp(self):
+        save_restore_converters(self)
         self.clinic = _make_clinic(filename="test.c")
 
     def test_eol(self):
@@ -2431,6 +2446,9 @@ def 
test_state_func_docstring_only_one_param_template(self):
 class ClinicExternalTest(TestCase):
     maxDiff = None
 
+    def setUp(self):
+        save_restore_converters(self)
+
     def run_clinic(self, *args):
         with (
             support.captured_stdout() as out,

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to