-
-
Notifications
You must be signed in to change notification settings - Fork 38
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
Run tests against a read-only "dashboard" database connection #18
Comments
I tried doing this in my import os
import pytest
from dj_database_url import parse
from django.conf import settings
from testing.postgresql import Postgresql
_POSTGRESQL = Postgresql()
@pytest.hookimpl(tryfirst=True)
def pytest_load_initial_conftests(early_config, parser, args):
os.environ["DJANGO_SETTINGS_MODULE"] = early_config.getini("DJANGO_SETTINGS_MODULE")
settings.DATABASES["default"] = parse(_POSTGRESQL.url())
settings.DATABASES["dashboard"] = parse(_POSTGRESQL.url())
settings.DATABASES["dashboard"]["OPTIONS"] = {
"options": "-c default_transaction_read_only=on -c statement_timeout=100"
}
def pytest_unconfigure(config):
_POSTGRESQL.stop() That's what triggered the above errors. |
https://pytest-django.readthedocs.io/en/latest/database.html#django-db-setup describes the
So maybe I need to over-ride that fixture for my project? Or I could try
|
The implementation of the |
I moved that logic to import pytest
@pytest.fixture(scope="session")
def django_db_modify_db_settings():
from django.conf import settings
settings.DATABASES["dashboard"]["OPTIONS"] = {
"options": "-c default_transaction_read_only=on -c statement_timeout=100"
} Just one catch: at the end of the tests I get these warnings:
|
Oh this is nasty: tests on my laptop are now flaky. Running |
CI is failing too: https://github.com/simonw/django-sql-dashboard/runs/2107262024 - lots of messages like this one:
|
https://github.com/django/django/blob/3.1.7/django/test/utils.py#L155-L196 is that |
Alternative idea: have the test framework create the default database as usual, then use the @pytest.fixture(autouse=True)
def use_dummy_cache_backend(settings):
settings.CACHES = {
"default": {
"BACKEND": "django.core.cache.backends.dummy.DummyCache",
}
} |
I tried that recipe but I got this error:
So I'm going to use an explicit fixture instead. |
Related to #16. I want to encourage using a separate
"dashboard"
database alias which is configured something like this:I want to write the tests against this - but I'm running into some trouble because the test framework isn't designed to handle read-only database connections like this. I'm seeing errors like this:
The text was updated successfully, but these errors were encountered: