bpo-42955: Add sys.modules_names (GH-24238)

Add sys.module_names, containing the list of the standard library
module names.
This commit is contained in:
Victor Stinner 2021-01-25 13:24:42 +01:00 committed by GitHub
parent 879986d8a9
commit db584bdad3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 305 additions and 275 deletions

View file

@ -334,8 +334,9 @@ class FaultHandlerTests(unittest.TestCase):
def test_dump_ext_modules(self):
code = """
import faulthandler
# _testcapi is a test module and not considered as a stdlib module
import _testcapi
import sys
# Don't filter stdlib module names
sys.module_names = frozenset()
faulthandler.enable()
faulthandler._sigsegv()
"""
@ -346,7 +347,8 @@ class FaultHandlerTests(unittest.TestCase):
if not match:
self.fail(f"Cannot find 'Extension modules:' in {stderr!r}")
modules = set(match.group(1).strip().split(', '))
self.assertIn('_testcapi', modules)
for name in ('sys', 'faulthandler'):
self.assertIn(name, modules)
def test_is_enabled(self):
orig_stderr = sys.stderr