diff options
author | Steve Dower <steve.dower@python.org> | 2022-02-02 19:54:27 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-02 19:54:27 (GMT) |
commit | 89a0a90c2e0e685bc70206fc45e4413c4f4411ed (patch) | |
tree | 118cc7fc62bd02c9c3ded9469446e74d831c43f8 /Lib | |
parent | e8659b47dece5a272111c0af5e340c364a9f807b (diff) | |
download | cpython-89a0a90c2e0e685bc70206fc45e4413c4f4411ed.zip cpython-89a0a90c2e0e685bc70206fc45e4413c4f4411ed.tar.gz cpython-89a0a90c2e0e685bc70206fc45e4413c4f4411ed.tar.bz2 |
bpo-46616: Ensures test_importlib.test_windows cleans up registry keys after completion (GH-31086)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_importlib/test_windows.py | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/Lib/test/test_importlib/test_windows.py b/Lib/test/test_importlib/test_windows.py index b3e8e7e..b7dfe86 100644 --- a/Lib/test/test_importlib/test_windows.py +++ b/Lib/test/test_importlib/test_windows.py @@ -60,17 +60,28 @@ def setup_module(machinery, name, path=None): root = machinery.WindowsRegistryFinder.REGISTRY_KEY key = root.format(fullname=name, sys_version='%d.%d' % sys.version_info[:2]) + base_key = "Software\\Python\\PythonCore\\{}.{}".format( + sys.version_info.major, sys.version_info.minor) + assert key.casefold().startswith(base_key.casefold()), ( + "expected key '{}' to start with '{}'".format(key, base_key)) try: with temp_module(name, "a = 1") as location: + try: + OpenKey(HKEY_CURRENT_USER, base_key) + if machinery.WindowsRegistryFinder.DEBUG_BUILD: + delete_key = os.path.dirname(key) + else: + delete_key = key + except OSError: + delete_key = base_key subkey = CreateKey(HKEY_CURRENT_USER, key) if path is None: path = location + ".py" SetValue(subkey, "", REG_SZ, path) yield finally: - if machinery.WindowsRegistryFinder.DEBUG_BUILD: - key = os.path.dirname(key) - delete_registry_tree(HKEY_CURRENT_USER, key) + if delete_key: + delete_registry_tree(HKEY_CURRENT_USER, delete_key) @unittest.skipUnless(sys.platform.startswith('win'), 'requires Windows') |