title: Unit Testing AWS python lambda global variable patch doesnt work
body: <p>I am trying to unit test Python based aws lambda code. I tried to use patch to mock environment variables but it throws error.How to handle global variables during unit testing. Any help is appreciated</p>
  
  <p>Tried @mock @patch but nothing seems to be working. When executing the testcase the values seems to be empty</p>
  
  <p>[registration.py]</p>
  
  <pre class="lang-py prettyprint-override"><code>    import os 
  
      #Global Variables
      DEBUG = os.environ.get("EnableLog")
      rest_endpoint = os.environ.get('restApiEndpoint')
      db_fn_endpoint = rest_endpoint+":3000/rpc/"
  
      def lambda_handler(event,context):
      return "success" #to see if this works
  
      if __name__ == "__main__":
          lambda_handler('', '')
  </code></pre>
  
  <p>Unit Test [test_registration.py]</p>
  
  <pre class="lang-py prettyprint-override"><code>    import json
      import pytest
      import sys, os
      from mock import patch
      from businesslogic import registration
  
      @mock.patch.dict(os.environ,{'EnableLog':'True'})
      @mock.patch.dict(os.environ,{'restApiEndpoint':'http://localhost'})
  
      @patch('registration.restApiEndpoint', 'http://localhost') 
  
  
      def test_lambda_handler():
         assert lambda_handler() =="success"
  
  </code></pre>
  
  <p>When I run pytest test_registration.py</p>
  
  <p>I get below exception </p>
  
  <pre><code>businesslogic\registration.py:6: in &lt;module&gt;
      db_fn_endpoint = rest_endpoint+":3000/rpc/"
  E   TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
  </code></pre>