diff --git a/Lib/test/test_clinic.py b/Lib/test/test_clinic.py index e81d3824e0ce28..3a0ff940d6a620 100644 --- a/Lib/test/test_clinic.py +++ b/Lib/test/test_clinic.py @@ -21,6 +21,20 @@ 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 @@ -107,6 +121,7 @@ def directive(self, name, args): 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): @@ -1369,6 +1384,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],