Exemplo n.º 1
0
def session_maker(engine):

    # run the tests with a separate external DB transaction
    # so that we can easily rollback all db changes (even if commited)
    # done by the test client

    # Note: that won't work when rollback is explictly called in the implementation

    # see also: https://docs.sqlalchemy.org/en/13/orm/session_transaction.html#joining-a-session-into-an-external-transaction-such-as-for-test-suites # noqa

    connection = engine.connect()
    trans = connection.begin()
    yield get_session_maker(connection)
    trans.rollback()
    connection.close()
Exemplo n.º 2
0
def session_maker(sql_connection, create_tables, auto_rollback):

    # run the tests with a separate external DB transaction
    # so that we can easily rollback all db changes (even if commited)
    # done by the test client

    # Note: when rollback is explictly called in the implementation,
    #       it will remove all objects created in the test even the ones
    #       that were already committed!

    # see also: https://docs.sqlalchemy.org/en/13/orm/session_transaction.html#joining-a-session-into-an-external-transaction-such-as-for-test-suites # noqa

    if auto_rollback:
        trans = sql_connection.begin()

    yield get_session_maker(sql_connection)

    if auto_rollback:
        trans.rollback()