-
Notifications
You must be signed in to change notification settings - Fork 347
Multi db tests behave differently on different dbs #423
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
Comments
Are you using IIRC Django only runs management commands (including migrations etc) on the default DB only. |
I'm not using
My second database has no migrations, so I assume Django only does |
I'll try to create a minimal working example to reproduce the issue on Monday |
OK I've created a repo with a minimal example that should demonstrate the issue https://github.com/obiwanus/pytest-django-bug Please let me know if you have any problems with it. Thanks |
I think a failing test (as a PR) would be better. But the above might be enough for others to look at already. |
Django only deals with the default database per default, as an optimization. Link to the doc I found this in pytest-django doc: https://github.com/pytest-dev/pytest-django/blob/master/docs/database.rst#tests-requiring-multiple-databases To implement the option in pytest-django without having to create classes, I hacked here: diff --git a/pytest_django/fixtures.py b/pytest_django/fixtures.py
index 692e061..e95122e 100644
--- a/pytest_django/fixtures.py
+++ b/pytest_django/fixtures.py
@@ -119,6 +119,7 @@ def _django_db_fixture_helper(transactional, request, django_db_blocker):
else:
from django.test import TestCase as django_case
+ django_case.multi_db = True
test_case = django_case(methodName='__init__')
test_case._pre_setup()
request.addfinalizer(test_case._post_teardown) We could enable this on demand with a |
@vbarbaresi |
I'll close this issue as a duplicate of general multi-db support. |
I have two identical sqlite databases for testing
At the start of each test the default database is clean, but the second database contains the data from the previous test runs.
The transaction setting
pytestmark = pytest.mark.django_db(transaction=True)
doesn't seem to have any effect on the default database behaviour - it is always clean for every test regardless of whethertransaction
isTrue
orFalse
. The same is true for the second database except it's always dirty.The text was updated successfully, but these errors were encountered: