title: python - UnboundLocalError: local variable referenced before assignment
body: <p>I am writing a unit test for a function.
  The function works perfectly on it self, but when I tried to test this function throught a unit test, it gives me a unbondlocalerror.
  I have rev_get_event define as a global variable </p>
  
  <pre><code>#return value for get event
  global rev_get_event
  
  def Get_event(username, password, eventID):
  try:
      payload = {'username': username, 'password': password}
      s = requests.Session()
      r = s.get("https://www.regonline.com/api/default.asmx/Login", params=payload)
      login_info = minidom.parseString(r.text)
  except requests.exceptions.RequestException:
      logger.exception("Requests error")
      api = login_info.getElementsByTagName('APIToken')
      for api_token in api:
          api_token = api_token.firstChild.nodeValue
      payload2 = {'eventID' : eventID, "apiToken" : api_token }
      rev_get_event = requests.get('https://www.regonline.com/api/default.asmx/GetEvent', params=payload2)
  except requests.exceptions.RequestException:
      logger.exception("Requests error")
  return rev_get_event
  </code></pre>
  
  <p>and my unit test is:</p>
  
  <pre><code>def test_get_event_good(self):
      result = rg.Get_event("eddietest", "eddietest", 18283)
      get_event = minidom.parseString(result)
      print result
      success = get_event.getElementsByTagName('Success') 
      for answer in success:
          answer = answer.firstChild.nodeValue
      self.assertEqual(answer, "true", "connetion failed")
  </code></pre>
  
  <p>and it gives me:</p>
  
  <pre><code>UnboundLocalError: local variable 'rev_get_event' referenced before assignment
  </code></pre>