def test_commit_fails_ctxmanager(self, local_connection):
    connection = local_connection
    transaction = [None]

    def go():
        with mock.patch.object(connection, '_commit_impl', mock.Mock(side_effect=exc.DBAPIError('failure', None, None, None))):
            with connection.begin() as t1:
                transaction[0] = t1
    assert_raises_message(exc.DBAPIError, 'failure', go)
    t1 = transaction[0]
    assert (not t1.is_active)
    with expect_warnings('transaction already deassociated from connection'):
        t1.rollback()
def test_commit_fails_ctxmanager(self, local_connection):
    connection = local_connection
    transaction = [None]

    def go():
        with mock.patch.object(connection, '_commit_impl', mock.Mock(side_effect=exc.DBAPIError('failure', None, None, None))):
            with connection.begin() as t1:
                transaction[0] = t1
    assert_raises_message(exc.DBAPIError, 'failure', go)
    t1 = transaction[0]
    assert (not t1.is_active)
    with expect_warnings('transaction already deassociated from connection'):
        t1.rollback()