title: Teardown issue using Moto DynamoDB and unittest in Python 3.8
body: <p>I'm trying to run some unit tests using <code>moto</code> and <code>unittest</code> based off of <a href="https://muhannad0.github.io/post/using-moto-to-mock-test-aws-a-dynamodb-example/" rel="nofollow noreferrer">this example</a> from muhannad0's blog.</p>
  <p>Below is my code (minified the table creation as it's not so important).</p>
  <pre class="lang-py prettyprint-override"><code>@mock_dynamodb2
  class TestDatabaseFunctions(unittest.TestCase):
  
      def setUp(self):
          &quot;&quot;&quot;
          Create database resource and mock table
          &quot;&quot;&quot;
          print(&quot;Setting up&quot;)
          self.dynamodb = boto3.resource('dynamodb', region_name='eu-west-2')
  
          self.table = self.dynamodb.create_table(TableName='test-table', KeySchema=[{'AttributeName': 'pk', 'KeyType': 'HASH'}, {'AttributeName': 'sk','KeyType': 'RANGE'}], AttributeDefinitions=[{'AttributeName': 'pk', 'AttributeType': 'S'},{'AttributeName': 'sk', 'AttributeType': 'S'}], ProvisionedThroughput={'ReadCapacityUnits': 1, 'WriteCapacityUnits': 1})
  
          print(&quot;Waiting until the table exists&quot;)
          # Wait until the table exists.
          self.table.meta.client.get_waiter('table_exists').wait(TableName='test-table')
          assert self.table.table_status == 'ACTIVE'
  
          print(&quot;Ready to go&quot;)
  
      def tearDown(self):
          &quot;&quot;&quot;
          Delete database resource and mock table
          &quot;&quot;&quot;
          print(&quot;Tearing down&quot;)
          self.table.delete()
          self.dynamodb = None
          print(&quot;Teardown complete&quot;)
  
      def test_table_exists(self):
          &quot;&quot;&quot;
          Test if our mock table is ready
          &quot;&quot;&quot;
          print(&quot;Testing&quot;)
          self.assertIn('test-table', self.table.name)
          print(&quot;Test complete&quot;)
  
  
  if __name__ == '__main__':
      unittest.main()
  </code></pre>
  <p>When I run it I end up with an error deep in Python 3.8's <code>mock.py</code> file.</p>
  <pre class="lang-none prettyprint-override"><code>=================================== FAILURES ===================================
  ___________________ TestDatabaseFunctions.test_table_exists ____________________
  ../../../env/lib/python3.8/site-packages/moto/core/models.py:102: in wrapper
      self.stop()
  ../../../env/lib/python3.8/site-packages/moto/core/models.py:86: in stop
      self.default_session_mock.stop()
  ../../../env/lib/python3.8/site-packages/mock/mock.py:1563: in stop
      return self.__exit__(None, None, None)
  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
  
  self = &lt;mock.mock._patch object at 0x1128d2a30&gt;, exc_info = (None, None, None)
  
      def __exit__(self, *exc_info):
          &quot;&quot;&quot;Undo the patch.&quot;&quot;&quot;
  &gt;       if self.is_local and self.temp_original is not DEFAULT:
  E       AttributeError: '_patch' object has no attribute 'is_local'
  
  ../../../env/lib/python3.8/site-packages/mock/mock.py:1529: AttributeError
  </code></pre>
  <p>Thanks to my caveman debugging I can say that this error happens after the <code>Teardown complete</code> message, suggesting that this is happening after the test executes successfully and is only happening after my teardown block finishes up.</p>
  <p>I quite like this example by muhannad0 as it uses the class decorator and lets us mock dynamodb in there easily so hopefully we can keep it.</p>
  <p>Let me know if you need any more information, you should be able to run this yourself by copying and pasting the code into your preferred IDE and hitting go.</p>