Skip to content

Commit e05831b

Browse files
vstinnermiss-islington
authored andcommitted
[3.12] pythongh-117347: Fix test_clinic side effects (pythonGH-117363) (pythonGH-117365)
pythongh-117347: Fix test_clinic side effects (pythonGH-117363) Save/restore converters in ClinicWholeFileTest and ClinicExternalTest. (cherry picked from commit c80d138) Co-authored-by: Victor Stinner <[email protected]> (cherry picked from commit 35b6c4a)
1 parent 01ab43c commit e05831b

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Lib/test/test_clinic.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,20 @@
2222
from clinic import DSLParser
2323

2424

25+
def restore_dict(converters, old_converters):
26+
converters.clear()
27+
converters.update(old_converters)
28+
29+
30+
def save_restore_converters(testcase):
31+
testcase.addCleanup(restore_dict, clinic.converters,
32+
clinic.converters.copy())
33+
testcase.addCleanup(restore_dict, clinic.legacy_converters,
34+
clinic.legacy_converters.copy())
35+
testcase.addCleanup(restore_dict, clinic.return_converters,
36+
clinic.return_converters.copy())
37+
38+
2539
class _ParserBase(TestCase):
2640
maxDiff = None
2741

@@ -108,6 +122,7 @@ def directive(self, name, args):
108122

109123
class ClinicWholeFileTest(_ParserBase):
110124
def setUp(self):
125+
save_restore_converters(self)
111126
self.clinic = clinic.Clinic(clinic.CLanguage(None), filename="test.c")
112127

113128
def expect_failure(self, raw):
@@ -1317,6 +1332,9 @@ class ClinicExternalTest(TestCase):
13171332
maxDiff = None
13181333
clinic_py = os.path.join(test_tools.toolsdir, "clinic", "clinic.py")
13191334

1335+
def setUp(self):
1336+
save_restore_converters(self)
1337+
13201338
def _do_test(self, *args, expect_success=True):
13211339
with subprocess.Popen(
13221340
[sys.executable, "-Xutf8", self.clinic_py, *args],

0 commit comments

Comments
 (0)