aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/support/os_helper.py
diff options
context:
space:
mode:
authorBénédikt Tran <10796600+picnixz@users.noreply.github.com>2025-03-16 14:09:33 +0100
committerGitHub <noreply@github.com>2025-03-16 14:09:33 +0100
commit3185e3115c918ec189e16cf9f5b51a13a0146556 (patch)
tree4a773847ee275359ae58832afea1071858e539af /Lib/test/support/os_helper.py
parent9558d22ac308c102e4f843541eead2022050225e (diff)
downloadcpython-3185e3115c918ec189e16cf9f5b51a13a0146556.tar.gz
cpython-3185e3115c918ec189e16cf9f5b51a13a0146556.zip
gh-131277: allow `EnvironmentVarGuard` to unset more than one environment variable at once (#131280)
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Diffstat (limited to 'Lib/test/support/os_helper.py')
-rw-r--r--Lib/test/support/os_helper.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/Lib/test/support/os_helper.py b/Lib/test/support/os_helper.py
index 15dcdc9b1fd..4e39b5a835a 100644
--- a/Lib/test/support/os_helper.py
+++ b/Lib/test/support/os_helper.py
@@ -720,9 +720,10 @@ else:
class EnvironmentVarGuard(collections.abc.MutableMapping):
+ """Class to help protect the environment variable properly.
- """Class to help protect the environment variable properly. Can be used as
- a context manager."""
+ Can be used as a context manager.
+ """
def __init__(self):
self._environ = os.environ
@@ -756,8 +757,10 @@ class EnvironmentVarGuard(collections.abc.MutableMapping):
def set(self, envvar, value):
self[envvar] = value
- def unset(self, envvar):
- del self[envvar]
+ def unset(self, envvar, /, *envvars):
+ """Unset one or more environment variables."""
+ for ev in (envvar, *envvars):
+ del self[ev]
def copy(self):
# We do what os.environ.copy() does.