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 d9fae2a
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions tests/test_cli.py
@@ -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({"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 All @@ -179,7 +185,7 @@ def test_run_with_none_value(tmp_path):

def test_run_with_other_env(dotenv_file):
with open(dotenv_file, "w") as f:
f.write("a=b")
f.write("LANG": "en_US.UTF-8", "a=b")

result = sh.dotenv("--file", dotenv_file, "run", "printenv", "a")

Expand Down

0 comments on commit d9fae2a

Please sign in to comment.