Skip to content
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

Upgrade to pytest-django 4.3.0 #109

Open
simonw opened this issue May 16, 2021 · 4 comments
Open

Upgrade to pytest-django 4.3.0 #109

simonw opened this issue May 16, 2021 · 4 comments
Labels

Comments

@simonw
Copy link
Owner

simonw commented May 16, 2021

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 simonw added the bug Something isn't working label May 16, 2021
@simonw
Copy link
Owner Author

simonw commented May 16, 2021

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
Copy link
Owner Author

simonw commented May 16, 2021

Their issue about this feature: pytest-dev/pytest-django#924

@simonw
Copy link
Owner Author

simonw commented May 16, 2021

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
Copy link
Owner Author

simonw commented May 16, 2021

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)

simonw added a commit that referenced this issue May 16, 2021
@simonw simonw added research and removed bug Something isn't working labels May 16, 2021
@simonw simonw changed the title Tests are broken on pytest-django 4.3.0 Upgrade to pytest-django 4.3.0 May 16, 2021
simonw added a commit that referenced this issue May 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant