|
43 | 43 | Py_GIL_DISABLED, |
44 | 44 | no_rerun, |
45 | 45 | force_not_colorized_test_class, |
| 46 | + catch_unraisable_exception |
46 | 47 | ) |
47 | 48 | from test.support.import_helper import ( |
48 | 49 | forget, make_legacy_pyc, unlink, unload, ready_to_import, |
@@ -1238,8 +1239,7 @@ def test_script_shadowing_stdlib_sys_path_modification(self): |
1238 | 1239 | stdout, stderr = popen.communicate() |
1239 | 1240 | self.assertRegex(stdout, expected_error) |
1240 | 1241 |
|
1241 | | - # TODO: RUSTPYTHON: _imp.create_dynamic is for C extensions, not applicable |
1242 | | - @unittest.skip("TODO: RustPython _imp.create_dynamic not implemented") |
| 1242 | + @unittest.expectedFailure # TODO: RUSTPYTHON; _imp.create_dynamic not implemented |
1243 | 1243 | def test_create_dynamic_null(self): |
1244 | 1244 | with self.assertRaisesRegex(ValueError, 'embedded null character'): |
1245 | 1245 | class Spec: |
@@ -2544,6 +2544,32 @@ def test_disallowed_reimport(self): |
2544 | 2544 | excsnap = _interpreters.run_string(interpid, script) |
2545 | 2545 | self.assertIsNot(excsnap, None) |
2546 | 2546 |
|
| 2547 | + @requires_subinterpreters |
| 2548 | + def test_pyinit_function_raises_exception(self): |
| 2549 | + # gh-144601: PyInit functions that raised exceptions would cause a |
| 2550 | + # crash when imported from a subinterpreter. |
| 2551 | + import _testsinglephase |
| 2552 | + filename = _testsinglephase.__file__ |
| 2553 | + script = f"""if True: |
| 2554 | + from test.test_import import import_extension_from_file |
| 2555 | +
|
| 2556 | + import_extension_from_file('_testsinglephase_raise_exception', {filename!r})""" |
| 2557 | + |
| 2558 | + interp = _interpreters.create() |
| 2559 | + try: |
| 2560 | + with catch_unraisable_exception() as cm: |
| 2561 | + exception = _interpreters.run_string(interp, script) |
| 2562 | + unraisable = cm.unraisable |
| 2563 | + finally: |
| 2564 | + _interpreters.destroy(interp) |
| 2565 | + |
| 2566 | + self.assertIsNotNone(exception) |
| 2567 | + self.assertIsNotNone(exception.type.__name__, "ImportError") |
| 2568 | + self.assertIsNotNone(exception.msg, "failed to import from subinterpreter due to exception") |
| 2569 | + self.assertIsNotNone(unraisable) |
| 2570 | + self.assertIs(unraisable.exc_type, RuntimeError) |
| 2571 | + self.assertEqual(str(unraisable.exc_value), "evil") |
| 2572 | + |
2547 | 2573 |
|
2548 | 2574 | class TestSinglePhaseSnapshot(ModuleSnapshot): |
2549 | 2575 | """A representation of a single-phase init module for testing. |
|
0 commit comments