Skip to content

Commit

Permalink
Copy existing environment for usage in tests
Browse files Browse the repository at this point in the history
Overriding the whole environment would remove critical variables like
`PYTHONPATH`. This would break tests on some systems like during Fedora
or Gentoo packaging.
  • Loading branch information
befeleme authored and bbc2 committed Apr 29, 2021
1 parent abde8e5 commit 7d9b45a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this
project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Fixed

- Fixed tests for build environments relying on `PYTHONPATH` (#318 by [@befeleme]).

## [0.17.0] - 2021-04-02

### Changed
Expand Down Expand Up @@ -232,6 +238,7 @@ project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
[@andrewsmith]: https://github.com/andrewsmith
[@asyncee]: https://github.com/asyncee
[@bbc2]: https://github.com/bbc2
[@befeleme]: https://github.com/befeleme
[@cjauvin]: https://github.com/cjauvin
[@earlbread]: https://github.com/earlbread
[@ekohl]: https://github.com/ekohl
Expand Down
16 changes: 8 additions & 8 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 @@ -143,8 +145,10 @@ def test_run_with_existing_variable(tmp_path):
dotenv_file = str(tmp_path / ".env")
with open(dotenv_file, "w") as f:
f.write("a=b")
env = dict(os.environ)
env.update({"LANG": "en_US.UTF-8", "a": "c"})

result = sh.dotenv("run", "printenv", "a", _env={"LANG": "en_US.UTF-8", "a": "c"})
result = sh.dotenv("run", "printenv", "a", _env=env)

assert result == "b\n"

Expand All @@ -154,14 +158,10 @@ def test_run_with_existing_variable_not_overridden(tmp_path):
dotenv_file = str(tmp_path / ".env")
with open(dotenv_file, "w") as f:
f.write("a=b")
env = dict(os.environ)
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"},
)
result = sh.dotenv("run", "--no-override", "printenv", "a", _env=env)

assert result == "c\n"

Expand Down

0 comments on commit 7d9b45a

Please sign in to comment.