-
Notifications
You must be signed in to change notification settings - Fork 346
Added support for multi_db #397
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
@@ -124,6 +125,7 @@ def _django_db_fixture_helper(transactional, request, django_db_blocker): | |||
from django.test import TestCase as django_case | |||
|
|||
test_case = django_case(methodName='__init__') | |||
test_case.multi_db = multi_db | |||
test_case._pre_setup() | |||
request.addfinalizer(test_case._post_teardown) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a more universal approach would be to get access to the Django TestCase, where you then could set multi_db
on. I will create a PR for that.
/cc @pelme
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
Heh, since from django.test import TestCase
TestCase.multi_db = True |
FWIW, I am using the following now as a workaround until something like this and/or #431 gets in: @pytest.fixture
def multi_db():
pass And in a plugin: def pytest_generate_tests(metafunc):
if 'multi_db' in metafunc.fixturenames:
# Enable Django's multi_db feature for tests globally.
# Can be improved after
# https://github.com/pytest-dev/pytest-django/pull/431.
if 'transactional_db' in metafunc.fixturenames:
from djanto.test import TransactionTestCase
TransactionTestCase.multi_db = True
else:
from django.test import TestCase
TestCase.multi_db = True (It could/should hook into / use |
@blueyed I made the changes you requested (I think :o) I still don't know how to write the tests for the new marker and fixture :/ |
Created a `django_multi_db` fixture and added a `multi_db` kwarg to the `django_db` marker.
Hello, I just updated this pull request :) I had difficulties making the marker work. The solution used here, to check for the marker in |
I like the approach here, unfortunately Thanks @pmourlanne! |
This adds support a marker and a fixture, that make tests behave like Django TestCase's multi_db class attribute (as defined in #76).
I added empty tests to test the added fixture and marker. I'm not sure how to implement them. I'm willing to try if you help me with a few pointers :>
(I have added the same kind of multi_db support for pytest-django 2.9.1, I can do another PR if you are interested)