Skip to content

Commit 7d9b45a

Browse files
befelemebbc2
authored andcommitted
Copy existing environment for usage in tests
Overriding the whole environment would remove critical variables like `PYTHONPATH`. This would break tests on some systems like during Fedora or Gentoo packaging.
1 parent abde8e5 commit 7d9b45a

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this
66
project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [Unreleased]
9+
10+
### Fixed
11+
12+
- Fixed tests for build environments relying on `PYTHONPATH` (#318 by [@befeleme]).
13+
814
## [0.17.0] - 2021-04-02
915

1016
### Changed
@@ -232,6 +238,7 @@ project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
232238
[@andrewsmith]: https://github.com/andrewsmith
233239
[@asyncee]: https://github.com/asyncee
234240
[@bbc2]: https://github.com/bbc2
241+
[@befeleme]: https://github.com/befeleme
235242
[@cjauvin]: https://github.com/cjauvin
236243
[@earlbread]: https://github.com/earlbread
237244
[@ekohl]: https://github.com/ekohl

tests/test_cli.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# -*- coding: utf-8 -*-
2+
import os
3+
24
import pytest
35
import sh
46

@@ -143,8 +145,10 @@ def test_run_with_existing_variable(tmp_path):
143145
dotenv_file = str(tmp_path / ".env")
144146
with open(dotenv_file, "w") as f:
145147
f.write("a=b")
148+
env = dict(os.environ)
149+
env.update({"LANG": "en_US.UTF-8", "a": "c"})
146150

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

149153
assert result == "b\n"
150154

@@ -154,14 +158,10 @@ def test_run_with_existing_variable_not_overridden(tmp_path):
154158
dotenv_file = str(tmp_path / ".env")
155159
with open(dotenv_file, "w") as f:
156160
f.write("a=b")
161+
env = dict(os.environ)
162+
env.update({"LANG": "en_US.UTF-8", "a": "c"})
157163

158-
result = sh.dotenv(
159-
"run",
160-
"--no-override",
161-
"printenv",
162-
"a",
163-
_env={"LANG": "en_US.UTF-8", "a": "c"},
164-
)
164+
result = sh.dotenv("run", "--no-override", "printenv", "a", _env=env)
165165

166166
assert result == "c\n"
167167

0 commit comments

Comments
 (0)