code: def with_environment(request):
      """Setup test environment for some functions that are tested
      in this module. In particular this functions stores attributes
      and other things that we need to stub in some test functions.
      This needs to be done on a function level and not module level because
      each testfunction needs a pristine environment.
      """
      GIVEN_ENV = {}
      GIVEN_ENV["env"] = env.copy()
      yield
      """Restore things that were remembered by the setup_environment function """
      orig_env = GIVEN_ENV["env"]
      # Pull keys out into list to avoid altering dictionary during iteration,
      # causing python 3 error
      for key in list(env.keys()):
          if key not in orig_env:
              del env[key]
      env.update(orig_env)
  
file_path: nibabel/nibabel/tests/test_environment.py
imports: import os
  from os import environ
  from os.path import abspath
  from os.path import join
  import pytest
  from ..None import environment
label_desc: Use image node_id 1 for calling a global function with example usage: with_environment(request) without return types