Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

gh-131277: allow EnvironmentVarGuard to unset more than one environment variable at once #131280

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 16, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Allow to unset more than one env var at once.
  • Loading branch information
picnixz committed Mar 15, 2025
commit 09c4aae7cb7ff89da690ce06e38662bcee3917c5
7 changes: 5 additions & 2 deletions 7 Doc/library/test.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1435,9 +1435,12 @@ The :mod:`test.support.os_helper` module provides support for os tests.
``value``.


.. method:: EnvironmentVarGuard.unset(envvar)
.. method:: EnvironmentVarGuard.unset(envvar, *others)

Temporarily unset the environment variable ``envvar``.
Temporarily unset one or more environment variables.

.. versionchanged:: next
More than one environment variable can be unset.


.. function:: can_symlink()
Expand Down
11 changes: 7 additions & 4 deletions 11 Lib/test/support/os_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -720,9 +720,10 @@ def temp_umask(umask):


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
Expand Down Expand Up @@ -756,8 +757,10 @@ def __len__(self):
def set(self, envvar, value):
self[envvar] = value

def unset(self, envvar):
del self[envvar]
def unset(self, envvar, /, *envvars):
"""Unset one or more known environment variables."""
picnixz marked this conversation as resolved.
Show resolved Hide resolved
for ev in (envvar, *envvars):
del self[ev]

def copy(self):
# We do what os.environ.copy() does.
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.