Skip to content

Commit 35b6c4a

Browse files
authored
gh-117347: Fix test_clinic side effects (#117363)
Save/restore converters in ClinicWholeFileTest and ClinicExternalTest.
1 parent 7e2fef8 commit 35b6c4a

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
@@ -52,6 +52,20 @@ def _expect_failure(tc, parser, code, errmsg, *, filename=None, lineno=None,
5252
return cm.exception
5353

5454

55+
def restore_dict(converters, old_converters):
56+
converters.clear()
57+
converters.update(old_converters)
58+
59+
60+
def save_restore_converters(testcase):
61+
testcase.addCleanup(restore_dict, clinic.converters,
62+
clinic.converters.copy())
63+
testcase.addCleanup(restore_dict, clinic.legacy_converters,
64+
clinic.legacy_converters.copy())
65+
testcase.addCleanup(restore_dict, clinic.return_converters,
66+
clinic.return_converters.copy())
67+
68+
5569
class ClinicWholeFileTest(TestCase):
5670
maxDiff = None
5771

@@ -60,6 +74,7 @@ def expect_failure(self, raw, errmsg, *, filename=None, lineno=None):
6074
filename=filename, lineno=lineno)
6175

6276
def setUp(self):
77+
save_restore_converters(self)
6378
self.clinic = _make_clinic(filename="test.c")
6479

6580
def test_eol(self):
@@ -2431,6 +2446,9 @@ def test_state_func_docstring_only_one_param_template(self):
24312446
class ClinicExternalTest(TestCase):
24322447
maxDiff = None
24332448

2449+
def setUp(self):
2450+
save_restore_converters(self)
2451+
24342452
def run_clinic(self, *args):
24352453
with (
24362454
support.captured_stdout() as out,

0 commit comments

Comments
 (0)