[Answered ]-How to test a Django view which has transaction.atomic(using=myDb)?

2👍

Figured it out, guys. The trick is to specify the db being used with a variable. The DATABASES key returns a different list depending on whether the code is running as a test or normally.

from django.conf import settings
if 'myDb' in settings.DATABASES:
    db = 'myDb'
else:
    db = 'default'
with transaction.atomic(using=db):
    ...

Leave a comment