Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-117347: Fix test_clinic side effects #117363

Merged
merged 1 commit into from
Mar 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Lib/test/test_clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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):
Expand Down Expand Up @@ -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,
Expand Down
Loading