Kaydet (Commit) 17814802 authored tarafından Miss Islington (bot)'s avatar Miss Islington (bot) Kaydeden (comit) Mariatta

bpo-31676: Fix test_imp.test_load_source() side effect (GH-3871) (GH-3988)

test_load_source() now replaces the current __name__ module with a
temporary module to prevent side effects.
(cherry picked from commit a505ecdc)
üst 98e0f26f
...@@ -315,8 +315,13 @@ class ImportTests(unittest.TestCase): ...@@ -315,8 +315,13 @@ class ImportTests(unittest.TestCase):
loader.get_data(imp.__file__) # Will need to create a newly opened file loader.get_data(imp.__file__) # Will need to create a newly opened file
def test_load_source(self): def test_load_source(self):
with self.assertRaisesRegex(ValueError, 'embedded null'): # Create a temporary module since load_source(name) modifies
imp.load_source(__name__, __file__ + "\0") # sys.modules[name] attributes like __loader___
modname = f"tmp{__name__}"
mod = type(sys.modules[__name__])(modname)
with support.swap_item(sys.modules, modname, mod):
with self.assertRaisesRegex(ValueError, 'embedded null'):
imp.load_source(modname, __file__ + "\0")
@support.cpython_only @support.cpython_only
def test_issue31315(self): def test_issue31315(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment