title: Stubbing an AWS Resource to raise a ClientError
body: <p>I have the following python code snippet (assuming the update_item arguments are valid):</p>
  <pre><code>#foo.py
  def update_table(value):
   dynamodb = boto3.resource('dynamodb')
       try:
           table = dynamodb.Table(&quot;test-table&quot;)
           response = table.update_item(Key=('value' : value)
       except botocore.exceptions.ClientError as err:
           return None
       return response
  </code></pre>
  <p>Now, I would like to write a unit test that test whether this function returns None when a valid arugments are passed but a ClientError is thrown.</p>
  <p>I mocked out a DynamoDB Table in a setUp function as shown:</p>
  <pre><code>#test_foo.py
  @mock_dynamodb2
  class TestUpdateTable(unittest.TestCase):
      
  
      def setUp(self):
          self.dynamodb = boto3.resource('dynamodb')
          
          # Creates a Mock Table
          self.table = self.dynamodb.create_table(
              TableName='test-table',
              KeySchema=[
                  {
                      'AttributeName': 'value',
                      'KeyType': 'HASH'
                  },
              ],
              AttributeDefinitions=[
                  {
                      'AttributeName': 'value',
                      'AttributeType': 'S'
                  },
              ],
              ProvisionedThroughput={
                  'ReadCapacityUnits': 5,
                  'WriteCapacityUnits': 5
          }
          )
  </code></pre>
  <p>and in my test function under this class:</p>
  <pre><code>def test_returns_none(self):
          stubber = Stubber(self.dynamodb.meta.client)
          stubber.add_client_error('update_item')
          
          stubber.activate()
          
          response = foo.update_table(&quot;123&quot;)
          stubber.deactivate()
  
          self.assertEqual(response, None)
  </code></pre>
  <p>Now, I expect this to properly stub out the table and raise a ClientError when calling the function to update the table. However, it seems like a ClientError is not raised and the response from the function that I'm testing is not = None as a ClientError is not raised.</p>
  <p>Anyone knows the reason for that? And how can I implement this test in a way so that the mock table will raise a ClientError and return None?</p>