bpo-39413: Implement os.unsetenv() on Windows (GH-18104)

The os.unsetenv() function is now also available on Windows.

It is implemented with SetEnvironmentVariableW(name, NULL).
This commit is contained in:
Victor Stinner 2020-01-21 16:13:09 +01:00 committed by GitHub
parent 59e2d26b25
commit 56cd3710a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 92 additions and 12 deletions

View file

@ -956,14 +956,9 @@ class EnvironTests(mapping_tests.BasicTestMappingProtocol):
# On OS X < 10.6, unsetenv() doesn't return a value (bpo-13415).
@support.requires_mac_ver(10, 6)
def test_unset_error(self):
if sys.platform == "win32":
# an environment variable is limited to 32,767 characters
key = 'x' * 50000
self.assertRaises(ValueError, os.environ.__delitem__, key)
else:
# "=" is not allowed in a variable name
key = 'key='
self.assertRaises(OSError, os.environ.__delitem__, key)
# "=" is not allowed in a variable name
key = 'key='
self.assertRaises(OSError, os.environ.__delitem__, key)
def test_key_type(self):
missing = 'missingkey'