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

223
Vistas
What is the best way to simulate disconnection within SQLAlchemy?

I write tests for CRUD application and I want to be sure that its behavior is correct in different scenarios when connection to database is lost permanently or temporarily.

For now, I patch session.execute in the middle of the session with OperationalError side_effect. Is there a better or more realistic simulation of connection interruption?

What I want to achieve looks like this:

 def test_interrupted_connection(self, client): query = text("SELECT 1") with sessionmaker.begin() as s: # Successful execute s.execute(query) # Failed execute with pytest.raises(OperationalError): # I guess here should be some monkeypatching or mocking # which will make SQLAlchemy think that connection # is lost during .execute() call below # But I don't know how it should look like. s.execute(query).
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You can invalidate the SQL connection using

 #db = create_engine('auth_url') #conn = db.connect() conn.invalidate() db.dispose(

But if you want to know how your application will behave in case of database failure, the best way to kill all your database connections. This usually happens when you scale your rds (there is a little downtime) and you will get No active database found error and then you can check your application behavior.

over 4 years ago · Santiago Trujillo Denunciar
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