diff options
author | Martin v. Löwis <martin@v.loewis.de> | 2009-06-07 17:55:17 (GMT) |
---|---|---|
committer | Martin v. Löwis <martin@v.loewis.de> | 2009-06-07 17:55:17 (GMT) |
commit | b7a515609d5029772243c1c7cda807cfd9bb9f4a (patch) | |
tree | cc01456c4402cfbb97b5b5cdf80bab1ddd709c1e /Lib | |
parent | 0a044e17bed98775070c8f1852620716fad71943 (diff) | |
download | cpython-b7a515609d5029772243c1c7cda807cfd9bb9f4a.zip cpython-b7a515609d5029772243c1c7cda807cfd9bb9f4a.tar.gz cpython-b7a515609d5029772243c1c7cda807cfd9bb9f4a.tar.bz2 |
Issue #6221: Delete test registry key before running the test.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_winreg.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/Lib/test/test_winreg.py b/Lib/test/test_winreg.py index 0b778b2..3b314dd 100644 --- a/Lib/test/test_winreg.py +++ b/Lib/test/test_winreg.py @@ -28,6 +28,27 @@ test_data = [ class WinregTests(unittest.TestCase): remote_name = None + def setUp(self): + # Make sure that the test key is absent when the test + # starts. + self.delete_tree(HKEY_CURRENT_USER, test_key_name) + + def delete_tree(self, root, subkey): + try: + hkey = OpenKey(root, subkey, KEY_ALL_ACCESS) + except WindowsError: + # subkey does not exist + return + while True: + try: + subsubkey = EnumKey(hkey, 0) + except WindowsError: + # no more subkeys + break + self.delete_tree(hkey, subsubkey) + CloseKey(hkey) + DeleteKey(root, subkey) + def WriteTestData(self, root_key, subkeystr="sub_key"): # Set the default value for this key. SetValue(root_key, test_key_name, REG_SZ, "Default value") |