-
Notifications
You must be signed in to change notification settings - Fork 347
Expose fixtures to change Django's {Transaction,}TestCase #431
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This adds `django_db_testcase` and `django_transactional_db_testcase`, which allows to override them to e.g. enable the `multi_db` feature: ``` @pytest.fixture def django_db_testcase(django_db_testcase): django_db_testcase.multi_db = True return django_db_testcase ``` Ref: pytest-dev#397
Not really required for This PR makes still sense, and is needed in case you want to use some specialized/derived class, especially since it's only required for a subset of tests usually: from django.test import TestCase
class MultiDbTestCase(TestCase):
multi_db = True
@pytest.fixture
def django_db_testcase():
return MultiDbTestCase |
Is there any way I could help with furthering the support for multiple databases? |
+1 |
We'd like to support read replicas on Amazon Aurora/Postgres and this is one impediment to doing it confidently. We have a vast test suite that would be a lot of work to rework with the Django TestCase. I've tried various versions of ideas suggested here and none seem to solve the multi-db problem. However, if I write a router with def db_for_read(self, model, **hints):
return "default"
def db_for_write(self, model, **hints):
return "default" it works as one would expect. Of course this doesn't really test multiple databases in the way one would want, but I think that's more of a system dynamics problem that I assume is accounted for (replica lag and it's ramifications). Any clarity on the "best" way to hack this in right now would also be appreciated, I see a few different examples but none seem to do it, that I've tried. |
In my opinion this is a bit of a cop-out, I'd like us to try and provide proper interfaces as much as we can. The major one ATM it seems is multi-db support ( |
This adds
django_db_testcase
anddjango_transactional_db_testcase
,which allows to override them to e.g. enable the
multi_db
feature:Ref: #397
TODO:
multi_db
feature (which requires to setup multiple DBs though)