-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix test pollution due to changing
os.environ
(#4)
- Loading branch information
Showing
4 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from __future__ import annotations | ||
|
||
import os | ||
|
||
from tests.helpers import isolated_environment | ||
|
||
|
||
def test_isolated_environment_restores_original_environ() -> None: | ||
original_environ = dict(os.environ) | ||
with isolated_environment(): | ||
os.environ["TEST_VAR"] = "test" | ||
assert os.environ == original_environ | ||
|
||
|
||
def test_isolated_environment_clears_environ() -> None: | ||
os.environ["TEST_VAR"] = "test" | ||
with isolated_environment(clear=True): | ||
assert "TEST_VAR" not in os.environ | ||
assert "TEST_VAR" in os.environ | ||
|
||
|
||
def test_isolated_environment_updates_environ() -> None: | ||
with isolated_environment(environ={"NEW_VAR": "new_value"}): | ||
assert os.environ["NEW_VAR"] == "new_value" | ||
assert "NEW_VAR" not in os.environ |