Skip to content

Commit 09c4aae

Browse files
committed
Allow to unset more than one env var at once.
1 parent 55815a6 commit 09c4aae

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

Doc/library/test.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,9 +1435,12 @@ The :mod:`test.support.os_helper` module provides support for os tests.
14351435
``value``.
14361436

14371437

1438-
.. method:: EnvironmentVarGuard.unset(envvar)
1438+
.. method:: EnvironmentVarGuard.unset(envvar, *others)
14391439

1440-
Temporarily unset the environment variable ``envvar``.
1440+
Temporarily unset one or more environment variables.
1441+
1442+
.. versionchanged:: next
1443+
More than one environment variable can be unset.
14411444

14421445

14431446
.. function:: can_symlink()

Lib/test/support/os_helper.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -720,9 +720,10 @@ def temp_umask(umask):
720720

721721

722722
class EnvironmentVarGuard(collections.abc.MutableMapping):
723+
"""Class to help protect the environment variable properly.
723724
724-
"""Class to help protect the environment variable properly. Can be used as
725-
a context manager."""
725+
Can be used as a context manager.
726+
"""
726727

727728
def __init__(self):
728729
self._environ = os.environ
@@ -756,8 +757,10 @@ def __len__(self):
756757
def set(self, envvar, value):
757758
self[envvar] = value
758759

759-
def unset(self, envvar):
760-
del self[envvar]
760+
def unset(self, envvar, /, *envvars):
761+
"""Unset one or more known environment variables."""
762+
for ev in (envvar, *envvars):
763+
del self[ev]
761764

762765
def copy(self):
763766
# We do what os.environ.copy() does.

0 commit comments

Comments
 (0)