lundi 7 novembre 2016

How do I prevent django from accessing a database during a test?

I'm trying to write a django health check for a cloud app to determine if the server is still healthy.

One of the checks determines if the database is still accessible. And I want to test if this works, so I'm writing a django test script to verify this.

Except django is really good at keeping a database connection.

Things which haven't worked:

Using override settings:

@override_settings(DATABASES={})
def test_dead_database(self):

Popping the default database settings:

    from django.conf import settings
    old_db_eng = settings.DATABASES.pop('default')

But Django keeps the database alive!

How can I force the django database to go away within a test?


edit: this is made more difficult as the test suite checks against a number of database engines - so I'd prefer a django focused solution.

Aucun commentaire:

Enregistrer un commentaire