title: Python unit test - NameError: name '' is not defined
body: <p>Using Python 3.x. 
  When running the test case for the following code, I get the error - 
  <code>NameError: name 'TEST_VAR' is not defined</code>. I am attaching the file to test, the yaml file the code is reading, and the unit test file. </p>
  
  <p>FileToTest.py: <a href="https://pastebin.com/d9QQiVSD" rel="nofollow noreferrer">https://pastebin.com/d9QQiVSD</a></p>
  
  <pre><code>from os import path
  from typing import TextIO
  from yaml import load as yload, SafeLoader
  
  TEST_FILE = "test.yaml"
  
  
  def retreiveFilePath(fpath, fname, write_mode=False) -&gt; TextIO:
      filePath = open("%(path)s/%(filename)s" % {
          "path": fpath,
          "filename": fname
      },
          "w" if write_mode else "r"
      )
      return filePath
  
  
  def methodToTest(val1, val2) -&gt; str:
      return "%(base)s/%(name)s/%(version)s.jar" % {
          "base": TEST_VAR["var1"]["var12"],
          "name": val1,
          "version": val2
      }
  
  
  def method1() -&gt; TextIO:
      try:
          filePath = retreiveFilePath(path.dirname(__file__), TEST_FILE)
          configReturn = yload(filePath.read())
          return configReturn
      except Exception as e:
          print("Failure, ", e)
      return None
  
  
  if __name__ == '__main__':
      try:
          TEST_VAR = method1()
      except Exception as err:
          exit_code = 1
      exit(exit_code)
  </code></pre>
  
  <p>yaml File: </p>
  
  <pre><code>var1:
    var12: someVal12
    var13: someVal13
  var2:
    var21: someVal21
  </code></pre>
  
  <p>test case: <a href="https://pastebin.com/crLymTHb" rel="nofollow noreferrer">https://pastebin.com/crLymTHb</a></p>
  
  <pre><code>import unittest
  
  from mock import patch
  
  import FileToTest
  
  class TestFile(unittest.TestCase):
  
      def test__get_artifact_url(self):
          val1 = "FName"
          val2 = "LName"
          resp = "someVal12/FName/LName.jar"
          target_resp = FileToTest.methodToTest(val1, val2)
          self.assertEqual(resp, target_resp)
  
  
  if __name__ == '__main__':
      unittest.main()
  </code></pre>
  
  <p>What would be the correct way to handle this situation? I tried using patch but to no vain.  </p>