title: How to test if SQL Alchemy transaction was called?
body: <p>How do I test following code, where engine is originally meant to be SQLAlchemy engine object?
  The test case I provided unfortunately doesn't work. I was able to check if the begin method of engine was called, but not the execute statement. The second <code>execute_mock</code> is never called after executing <code>fetch_data</code> method.</p>
  
  <pre><code>class A():
      def __init__(self, engine):
          self.engine = engine
  
      def fetch_data(self):
          with self.engine.begin() as trans:
              trans.execute("SELECT * FROM XXX")
  
  from unittest.mock import MagicMock
  def test_A():
      execute_mock = MagicMock()
      engine_mock = MagicMock()
      engine_mock.begin.return_value.execute = execute_mock
  
      A(engine_mock)
      execute_mock.assert_not_called()
      A.fetch_data()
      execute_mock.assert_called_with("SELECT * FROM XXX")
  </code></pre>