Skip to content

Commit

Permalink
Fix Windows environment issues in tests instead of functions.
Browse files Browse the repository at this point in the history
The issue might be too specific to require this fix.
Something like a warning might be better.
  • Loading branch information
HexDecimal authored and kvas-it committed May 15, 2023
1 parent f62702e commit 7c0be8a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
7 changes: 0 additions & 7 deletions pytest_console_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,13 +281,6 @@ def run_subprocess(
if _is_nonexecutable_python_file(script_path):
cmd_args = [sys.executable or 'python'] + cmd_args

env: dict[str, str] | None = options.get("env")
# Prevent _Py_HashRandomization_Init failure on Windows
if env is not None and "SYSTEMROOT" in os.environ:
env = env.copy()
env.setdefault("SYSTEMROOT", os.environ["SYSTEMROOT"])
options["env"] = env

cp = subprocess.run(
cmd_args,
input=stdin_input,
Expand Down
7 changes: 5 additions & 2 deletions tests/test_run_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ def test_elsewhere_in_the_path(
console_script: Path, script_runner: ScriptRunner
) -> None:
console_script.chmod(0o777)
env = {'PATH': f"{console_script.parent}{os.pathsep}{os.environ['PATH']}"}
env = os.environ.copy()
env["PATH"] = f"{console_script.parent}{os.pathsep}{env['PATH']}"
result = script_runner.run(console_script.name, env=env)
assert result.success
assert result.stdout == 'foo\n'
Expand Down Expand Up @@ -187,7 +188,9 @@ def test_env(console_script: Path, script_runner: ScriptRunner) -> None:
os.environ['FOO'] = 'baz'
"""
)
result = script_runner.run(str(console_script), env={'FOO': 'bar'})
env = os.environ.copy()
env['FOO'] = 'bar'
result = script_runner.run(str(console_script), env=env)
assert result.success
assert result.stdout == 'bar\n'
assert 'FOO' not in os.environ
Expand Down

0 comments on commit 7c0be8a

Please sign in to comment.