INNER CODE UNIT · Python

sqla_reflection

dialoguemd/fastapi-sqla · fastapi_sqla/_pytest_plugin.py:104

def sqla_reflection(sqla_modules, sqla_connection: Connection):
    import fastapi_sqla  # noqa: PLC0415

    fastapi_sqla.Base.metadata.bind = sqla_connection  # type: ignore
    fastapi_sqla.Base.prepare(sqla_connection.engine)


@fixture
def patch_new_engine(request: FixtureRequest, sqla_connection: Connection):
    """So that all DB operations are never written to db for real."""
    if "dont_patch_engines" in request.keywords:
        yield
    else:
        with sqla_connection.begin() as transaction:
            with patch("fastapi_sqla.sqla.new_engine", return_value=sqla_connection):
                yield

            transaction.rollback()

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…