dont reassign os.environ

os.environ is an `environ` object, not a dict. by only interacting with
it through builtin functions we can ensure it remains properly
accessible to third party libraries which might interact with it in
different ways.

See https://github.com/alphagov/notifications-api/commit/d2441466 for
more detail
This commit is contained in:
Leo Hemsted
2020-01-07 11:54:10 +00:00
parent 39ec952c45
commit 91adadfed0
3 changed files with 15 additions and 12 deletions

View File

@@ -6,12 +6,11 @@ from app.cloudfoundry_config import extract_cloudfoundry_config
@pytest.fixture
def cloudfoundry_environ(monkeypatch):
monkeypatch.setenv('VCAP_APPLICATION', '{"space_name":"🚀🌌"}')
def cloudfoundry_environ(os_environ):
os.environ['VCAP_APPLICATION'] = '{"space_name":"🚀🌌"}'
@pytest.mark.usefixtures('os_environ', 'cloudfoundry_environ')
def test_extract_cloudfoundry_config_populates_other_vars():
def test_extract_cloudfoundry_config_populates_other_vars(cloudfoundry_environ):
extract_cloudfoundry_config()
assert os.environ['NOTIFY_ENVIRONMENT'] == '🚀🌌'