mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-76785: Return an "excinfo" Object From Interpreter.run() (gh-111573)
This commit is contained in:
parent
14e539f097
commit
9e56eedd01
9 changed files with 433 additions and 258 deletions
|
@ -655,25 +655,19 @@ class MagicNumberTests(unittest.TestCase):
|
|||
@unittest.skipIf(_interpreters is None, 'subinterpreters required')
|
||||
class IncompatibleExtensionModuleRestrictionsTests(unittest.TestCase):
|
||||
|
||||
ERROR = re.compile("^ImportError: module (.*) does not support loading in subinterpreters")
|
||||
|
||||
def run_with_own_gil(self, script):
|
||||
interpid = _interpreters.create(isolated=True)
|
||||
try:
|
||||
_interpreters.run_string(interpid, script)
|
||||
except _interpreters.RunFailedError as exc:
|
||||
if m := self.ERROR.match(str(exc)):
|
||||
modname, = m.groups()
|
||||
raise ImportError(modname)
|
||||
excsnap = _interpreters.run_string(interpid, script)
|
||||
if excsnap is not None:
|
||||
if excsnap.type.__name__ == 'ImportError':
|
||||
raise ImportError(excsnap.msg)
|
||||
|
||||
def run_with_shared_gil(self, script):
|
||||
interpid = _interpreters.create(isolated=False)
|
||||
try:
|
||||
_interpreters.run_string(interpid, script)
|
||||
except _interpreters.RunFailedError as exc:
|
||||
if m := self.ERROR.match(str(exc)):
|
||||
modname, = m.groups()
|
||||
raise ImportError(modname)
|
||||
excsnap = _interpreters.run_string(interpid, script)
|
||||
if excsnap is not None:
|
||||
if excsnap.type.__name__ == 'ImportError':
|
||||
raise ImportError(excsnap.msg)
|
||||
|
||||
@unittest.skipIf(_testsinglephase is None, "test requires _testsinglephase module")
|
||||
def test_single_phase_init_module(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue