Skip to content

Commit

Permalink
Copy existing environment for usage in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
befeleme committed Apr 29, 2021
1 parent abde8e5 commit 13303ca
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# -*- coding: utf-8 -*-
import os

import pytest
import sh

Expand Down Expand Up @@ -144,7 +146,9 @@ def test_run_with_existing_variable(tmp_path):
with open(dotenv_file, "w") as f:
f.write("a=b")

result = sh.dotenv("run", "printenv", "a", _env={"LANG": "en_US.UTF-8", "a": "c"})
test_env = dict(os.environ)
test_env.update({"LANG": "en_US.UTF-8", "a": "c"})
result = sh.dotenv("run", "printenv", "a", _env=test_env)

assert result == "b\n"

Expand All @@ -155,12 +159,14 @@ def test_run_with_existing_variable_not_overridden(tmp_path):
with open(dotenv_file, "w") as f:
f.write("a=b")

test_env = dict(os.environ)
test_env.update({"LANG": "en_US.UTF-8", "a": "c"})
result = sh.dotenv(
"run",
"--no-override",
"printenv",
"a",
_env={"LANG": "en_US.UTF-8", "a": "c"},
_env=test_env,
)

assert result == "c\n"
Expand Down

0 comments on commit 13303ca

Please sign in to comment.