diff options
author | Marcel Plch <gmarcel.plch@gmail.com> | 2018-03-17 05:41:20 (GMT) |
---|---|---|
committer | Nick Coghlan <ncoghlan@gmail.com> | 2018-03-17 05:41:20 (GMT) |
commit | c2b0b12d1a137ada1023ab7c10b8d9a0249d95f9 (patch) | |
tree | 53b82a27d468a5fc63067d3d1ecbd186388666f9 /Lib/test/test_importlib/extension | |
parent | d6e140466142018ddbb7541185348be2b833a2ce (diff) | |
download | cpython-c2b0b12d1a137ada1023ab7c10b8d9a0249d95f9.zip cpython-c2b0b12d1a137ada1023ab7c10b8d9a0249d95f9.tar.gz cpython-c2b0b12d1a137ada1023ab7c10b8d9a0249d95f9.tar.bz2 |
bpo-32374: m_traverse may be called with m_state=NULL (GH-5140)
Multi-phase initialized modules allow m_traverse to be called while the
module is still being initialized, so module authors may need to account
for that.
Diffstat (limited to 'Lib/test/test_importlib/extension')
-rw-r--r-- | Lib/test/test_importlib/extension/test_loader.py | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/Lib/test/test_importlib/extension/test_loader.py b/Lib/test/test_importlib/extension/test_loader.py index 8d20040..53ac3c7 100644 --- a/Lib/test/test_importlib/extension/test_loader.py +++ b/Lib/test/test_importlib/extension/test_loader.py @@ -9,7 +9,7 @@ import types import unittest import importlib.util import importlib - +from test.support.script_helper import assert_python_failure class LoaderTests(abc.LoaderTests): @@ -267,6 +267,20 @@ class MultiPhaseExtensionModuleTests(abc.LoaderTests): self.assertEqual(module.__name__, name) self.assertEqual(module.__doc__, "Module named in %s" % lang) + @unittest.skipIf(not hasattr(sys, 'gettotalrefcount'), + '--with-pydebug has to be enabled for this test') + def test_bad_traverse(self): + ''' Issue #32374: Test that traverse fails when accessing per-module + state before Py_mod_exec was executed. + (Multiphase initialization modules only) + ''' + script = """if True: + import importlib.util as util + spec = util.find_spec('_testmultiphase') + spec.name = '_testmultiphase_with_bad_traverse' + m = spec.loader.create_module(spec)""" + assert_python_failure("-c", script) + (Frozen_MultiPhaseExtensionModuleTests, Source_MultiPhaseExtensionModuleTests |