django-sql-dashboard icon indicating copy to clipboard operation
django-sql-dashboard copied to clipboard

Upgrade to pytest-django 4.3.0

Open simonw opened this issue 4 years ago • 4 comments
trafficstars

The tests are currently failing. The difference looks to be pytest-django 4.3.0.

The last tests that passed show this:

platform linux -- Python 3.8.10, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
django: settings: config.settings (from env)
rootdir: /home/runner/work/django-sql-dashboard/django-sql-dashboard, configfile: pytest.ini
plugins: pythonpath-0.7.3, django-4.2.0

The tests that now fail show:

platform linux -- Python 3.8.10, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
django: settings: config.settings (from env)
rootdir: /home/runner/work/django-sql-dashboard/django-sql-dashboard, configfile: pytest.ini
plugins: pythonpath-0.7.3, django-4.3.0

simonw avatar May 16 '21 00:05 simonw

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:

simonw avatar May 16 '21 00:05 simonw

Their issue about this feature: https://github.com/pytest-dev/pytest-django/issues/924

simonw avatar May 16 '21 00:05 simonw

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.

simonw avatar May 16 '21 00:05 simonw

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
 
 
[email protected]
-def dashboard_db(settings, db):
[email protected](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)

simonw avatar May 16 '21 00:05 simonw