code: def test_with_environment():
      name1 = "MXNET_TEST_ENV_VAR_1"
      name2 = "MXNET_TEST_ENV_VAR_2"
  
      def check_background_values():
          assert_equal(os.environ.get(name1), "10")
          assert_equal(getenv(name1), "10")
          assert_equal(os.environ.get(name2), None)
          assert_equal(getenv(name2), None)
  
      check_background_values()
  
      # This completes the testing of with_environment(), but since we have
      # an environment with a couple of known settings, lets use it to test if
      # 'with environment()' properly restores to these settings in all cases.
  
      class OnPurposeError(Exception):
          """A class for exceptions thrown by this test"""
  
          pass
  
      # Enter an environment with one variable set and check it appears
      # to both python and the backend.  Then, outside the 'with' block,
      # make sure the background environment is seen, regardless of whether
      # the 'with' block raised an exception.
      def test_one_var(name, value, raise_exception=False):
          try:
              with environment(name, value):
                  assert_equal(os.environ.get(name), value)
                  assert_equal(getenv(name), value)
                  if raise_exception:
                      raise OnPurposeError
          except OnPurposeError:
              pass
          finally:
              check_background_values()
  
      # Test various combinations of set and unset env vars.
      # Test that the background setting is restored in the presense of exceptions.
      for raise_exception in [False, True]:
          # name1 is initially set in the environment
          test_one_var(name1, "42", raise_exception)
          test_one_var(name1, None, raise_exception)
          # name2 is initially not set in the environment
          test_one_var(name2, "42", raise_exception)
          test_one_var(name2, None, raise_exception)
  
file_path: mxnet/tests/python/unittest/test_base.py
imports: import mxnet
  from numpy.testing import assert_equal
  from mxnet.base import data_dir
  from mxnet.test_utils import environment
  from mxnet.util import getenv
  from common import with_environment
  import os
  import logging
  import os.path
  import platform
  import pytest
label_desc: Use image node_id 2 for calling a global function with example usage: test_with_environment() without return types