Open simonw opened 3 years ago
Test failures look like this:
E AssertionError: Database queries to 'dashboard' are not allowed in this test. Add 'dashboard' to pytest_django.fixtures._django_db_fixture_helper.<locals>.PytestDjangoTestCase.databases to ensure proper test isolation and silence this failure.
https://pytest-django.readthedocs.io/en/latest/changelog.html#v4-3-0-2021-05-15 says:
- Add experimental multiple databases (multi db) support.
Their issue about this feature: https://github.com/pytest-dev/pytest-django/issues/924
For the moment I'm going to pin to 4.2.0 - I'll leave this issue open as an "upgrade to 4.3.0" task.
I tried fixing it like this but it didn't work:
diff --git a/conftest.py b/conftest.py
index 4354a71..aaa24e6 100644
--- a/conftest.py
+++ b/conftest.py
@@ -4,11 +4,13 @@ from django.contrib.auth.models import Permission
from django_sql_dashboard.models import Dashboard
-@pytest.fixture
-def dashboard_db(settings, db):
+@pytest.fixture(autouse=True)
+def django_db_setup(django_db_setup, settings, request, django_db_blocker):
settings.DATABASES["dashboard"]["OPTIONS"] = {
"options": "-c default_transaction_read_only=on -c statement_timeout=100"
}
+ django_db_blocker.unblock()
+ request.addfinalizer(django_db_blocker.restore)
The tests are currently failing. The difference looks to be pytest-django 4.3.0.
The last tests that passed show this:
The tests that now fail show: