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

[3.11] [3.12] gh-117347: Fix test_clinic side effects (GH-117363) (GH-117365) #117366

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions Lib/test/test_clinic.py
Expand Up @@ -22,6 +22,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

Expand Down Expand Up @@ -108,6 +122,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):
Expand Down Expand Up @@ -1317,6 +1332,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],
Expand Down