diff --git a/README.rst b/README.rst index 18f12b4..a52d492 100644 --- a/README.rst +++ b/README.rst @@ -71,6 +71,14 @@ or simply by changing its attributes: # Globally disables SQL caching until you set it back to True cachalot_settings.CACHALOT_ENABLED = False + from django.test import TestCase + + @cachalot_settings(CACHALOT_ENABLED=True) + class YourTestCase(TestCase): + # SQL caching is enabled again in every method of this test + + # SQL caching is disabled again because we globally disabled it + In tests, you can use `Django’s testing tools `_ as well as ``cachalot_settings``. They will both work the same. diff --git a/cachalot/tests.py b/cachalot/tests.py index 6a14ef6..5991b52 100644 --- a/cachalot/tests.py +++ b/cachalot/tests.py @@ -1181,14 +1181,23 @@ class AtomicTestCase(TestCase): self.assertListEqual(data3, [t1]) -class SettingsTestCase(TestCase): - @cachalot_settings(CACHALOT_ENABLED=False) - def test_decorator(self): +@cachalot_settings(CACHALOT_ENABLED=False) +class SettingsDecoratorTestCase(TestCase): + def test_class(self): with self.assertNumQueries(1): list(Test.objects.all()) with self.assertNumQueries(1): list(Test.objects.all()) + @cachalot_settings(CACHALOT_ENABLED=True) + def test_method(self): + with self.assertNumQueries(1): + list(Test.objects.all()) + with self.assertNumQueries(0): + list(Test.objects.all()) + + +class SettingsTestCase(TestCase): def test_enabled(self): with cachalot_settings(CACHALOT_ENABLED=True): with self.assertNumQueries(1):