Skip to content
Myr

Fix test runner not saving caller env correctly

Before adoption: this commit came in with the history the project adopted, so no landing records it.

isolate() captures current env variable values, overwrites them, yields, then restores them. Unfortunately the capturing code was broken and the env variables were wiped out during the restore phase.

authored by Patrick Mézard · committed by Markus Unterwaditzer · parent 891a223 · Browse files · 2 files+20 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+20 added−1 removed

  • tests:+19 added−0 removed
  • other:+1 added−1 removed

2 files+20 added−1 removed

modified:click/testing.py+1 added-1 removed
211 unmodified lines
212213 old_env = {}214 try:215 for key, value in iteritems(env):216 old_env[key] = os.environ.get(value)216 old_env[key] = os.environ.get(key)217 if value is None:218 try:219 del os.environ[key]220 except Exception:
102 unmodified lines
modified:tests/test_testing.py+19 added
1import os2import sys34import pytest5import click
177 unmodified lines
183184 result = runner.invoke(cli_no_error)185 assert result.exit_code == 0186 assert result.output == 'hello world\n'187188189def test_env():190 @click.command()191 def cli_env():192 click.echo('ENV=%s' % os.environ['TEST_CLICK_ENV'])193194 runner = CliRunner()195196 env_orig = dict(os.environ)197 env = dict(env_orig)198 assert 'TEST_CLICK_ENV' not in env199 env['TEST_CLICK_ENV'] = 'some_value'200 result = runner.invoke(cli_env, env=env)201 assert result.exit_code == 0202 assert result.output == 'ENV=some_value\n'203204 assert os.environ == env_orig