Closed treyhunner closed 1 year ago
Settings typically don't change during production but yes this is a good point to override. Cachalot patches the Django ORM on startup. Something you can use instead is cachalot.api.cachalot_disabled
This is less so of a bug, but semantically a feature to be implemented I suppose... However, I believe utilizing the context manager/decorator is more suitable, so closing.
I solved it by triggering a reload in a fixture:
from django.test.utils import override_settings
from cachalot.settings import cachalot_settings
import pytest
@pytest.fixture
@override_settings(CACHALOT_ENABLED=False)
def disable_caching() -> None:
cachalot_settings.reload()
def test_something(disable_caching: None):
pass
....
What happened?
I'm using freezegun, so I'm affected by #126.
When I set
CACHALOT_ENABLED= False
in my settings, my tests pass.I'd prefer to use cachalot for most of my tests and only disable it for the tests where freezegun is used. When I use
override_settings(CACHALOT_ENABLED=False)
, the setting does change but the queries with the test are still cached.What should've happened instead?
Using the
override_settings
decorator to disableCACHALOT_ENABLED
should have disabled caching during the decorated test.Steps to reproduce
Use the
@override_settings(CACHALOT_ENABLED=False)
decorator on a test that usesfreezegun.freeze_time
for a long past date. When calling therefresh_from_db()
method on a model instance, the instance will not refresh even if it has been changed.I'm using Docker with Postgres and on Django 3.2.7.