Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

259
Vistas
FastAPI endpoint test - database session not sync

I have an issue when I test my API, the DB session at the tests isn't up to date when performing post request.

For example:

@pytest.fixture(scope="module")
def db(engine, tables, users) -> Generator:
    """Returns an sqlalchemy session, and after the test tears down everything properly."""
    try:
        db = TestingSessionLocal()
        yield db
    finally:
        db.close()
def test_test(client: TestClient, db: Session):
    item_id = 1
    params = {
        "item_id": item_id,
    }

    r = client.post("/endpoint",json=params)
    db2: SessionLocal = TestingSessionLocal()  # TEMP SOLUTION
    # item_from_db = service.table.get(db, item_id)  # TODO:  make it work!!
    item_from_db = service.event.get(db2, item_id)
    db2.close()

I see the new item at my DB at run time, but I cant get it with the fixture. Only when I create a new connection to DB, I manage to get the new item I added.

over 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda