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

Add a Test to Verify All Stdlib Modules Can Be Imported in an Isolated Subinterpreter #104289

Open
ericsnowcurrently opened this issue May 8, 2023 · 1 comment
Labels
3.12 bugs and security fixes extension-modules C modules in the Modules dir tests Tests in the Lib/test dir topic-subinterpreters type-feature A feature request or enhancement

Comments

@ericsnowcurrently
Copy link
Member

(This is a follow-up to gh-103092 and gh-104108.)

It may be worth having a test that tries importing every stdlib module in a subinterpreter that has its own GIL. This would ensure that all our builtin/extension modules are isolated (implement multi-phase init and have a Py_MOD_PER_INTERPRETER_GIL_SUPPORTED slot).

(Such a test should fail until gh-103092 is finished.)

@ericsnowcurrently ericsnowcurrently added type-feature A feature request or enhancement extension-modules C modules in the Modules dir topic-subinterpreters 3.12 bugs and security fixes labels May 8, 2023
@tonybaloney
Copy link
Contributor

This is the script I'm using to do this:

from test.libregrtest.findtests import findtests

import _xxsubinterpreters as interpreters

# Get a list of tests
test_names = findtests()
skip_tests = [
    "test_httpservers", # hangs?
    "test_imaplib" # hangs?
]


def run_test():
    import unittest

    test_cases = unittest.defaultTestLoader.loadTestsFromName(f"test.{test_name}")
    reasons = ""
    pass_count = 0
    fail_count = 0
    for case in test_cases:
        r = unittest.result.TestResult()
        case.run(r)
        if r.wasSuccessful():
            pass_count += r.testsRun
        else:
            for failedcase, reason in r.failures:
                reasons += "---------------------------------------------------------------\n"
                reasons += f"Test case {failedcase} failed:\n"
                reasons += reason
                reasons += "\n---------------------------------------------------------------\n"
                fail_count += 1

            for failedcase, reason in r.errors:
                reasons += (
                    "---------------------------------------------------------------\n"
                )
                reasons += f"Test case {failedcase} failed with errors:\n"
                reasons += reason
                reasons += "\n---------------------------------------------------------------\n"
                fail_count += 1
    print(f"Test {test_name} passed {pass_count} tests and failed {fail_count} tests")
    if fail_count > 0:
        print(reasons)

interp = interpreters.create()

for test in test_names:
    # Run the test suite
    if test in skip_tests:
        print(f"Skipping test {test}")
        continue
    print(f"Running test {test}")
    try:
        result = interpreters.run_func(interp, run_test, shared={"test_name": test})
    except Exception as e:
        print(f"Test {test} failed with exception {e}")
        continue

@ericsnowcurrently ericsnowcurrently added the tests Tests in the Lib/test dir label Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.12 bugs and security fixes extension-modules C modules in the Modules dir tests Tests in the Lib/test dir topic-subinterpreters type-feature A feature request or enhancement
Projects
Status: Todo
Development

No branches or pull requests

2 participants