Skip to content

Commit

Permalink
Clone environment only once.
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Prescod committed Apr 14, 2023
1 parent 7a263a0 commit aa56206
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions cumulusci/tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,19 @@ def _init_task():
yield


# copy over most of the environment because Windows needs something
# non-obvious and it is quite laborius to figure out what it is.

# but we want to hide the CUMULUSCI_ and GITHUB_ related stuff from tests.
ENV_CLONE = {
key: value
for key, value in os.environ.items()
if "CUMULUSCI_" not in key and "GITHUB_" not in key
}

ENV_CLONE["CUMULUSCI_SYSTEM_CERTS"] = "True"


@contextmanager
def mock_env(
home,
Expand All @@ -271,20 +284,8 @@ def mock_env(
"HOME": home,
"USERPROFILE": home,
"REAL_HOME": real_homedir,
"CUMULUSCI_SYSTEM_CERTS": "True",
"PATH": os.environ["PATH"],
}
if pythonpath := os.environ.get("PYTHONPATH"):
new_environment["PYTHONPATH"] = pythonpath

# copy over all of the environment ones because Windows
# needs something not listed above and I don't know what
# it is.
for key, value in os.environ.items():
if "CUMULUSCI_" not in key and "GITHUB_" not in key:
new_environment[key] = value

# among other things, this will hide CUMULUSCI_KEY and CUMULUSCI_SERVICE_github
}.update(ENV_CLONE)

with mock.patch("pathlib.Path.home", lambda: Path(home)), mock.patch.dict(
os.environ, new_environment, clear=True
):
Expand Down

0 comments on commit aa56206

Please sign in to comment.