forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Save env vars at first pytest hook to ensure theyre unedited (#22344)
fixes #22192. Now, all environment variables are accessed during the pytest_load_initial_conftests hook and then saved as global variables in the plugin. This ensures the port and uuid will still be saved even if a user safely or unsafely clears their environment variables during testing. --------- Co-authored-by: Karthik Nadig <[email protected]>
- Loading branch information
1 parent
c2dec14
commit 71a451c
Showing
4 changed files
with
146 additions
and
40 deletions.
There are no files selected for viewing
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,32 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
|
||
import os | ||
|
||
|
||
def test_clear_env(monkeypatch): | ||
# Clear all environment variables | ||
monkeypatch.setattr(os, "environ", {}) | ||
|
||
# Now os.environ should be empty | ||
assert not os.environ | ||
|
||
# After the test finishes, the environment variables will be reset to their original state | ||
|
||
|
||
def test_check_env(): | ||
# This test will have access to the original environment variables | ||
assert "PATH" in os.environ | ||
|
||
|
||
def test_clear_env_unsafe(): | ||
# Clear all environment variables | ||
os.environ.clear() | ||
# Now os.environ should be empty | ||
assert not os.environ | ||
|
||
|
||
def test_check_env_unsafe(): | ||
# ("PATH" in os.environ) is False here if it runs after test_clear_env_unsafe. | ||
# Regardless, this test will pass and TEST_PORT and TEST_UUID will still be set correctly | ||
assert "PATH" not in os.environ |
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