diff --git a/testapp/tests.py b/testapp/tests.py index 79b6e19..c6f3ea5 100644 --- a/testapp/tests.py +++ b/testapp/tests.py @@ -4,6 +4,10 @@ from .models import TestModel +def clear_contenttype_cache(): + print("Clearing content type cache...") + ContentType.objects.clear_cache() + class ContentTypeCacheTestCase(ChannelsLiveServerTestCase): """ Test case that demonstrates ContentType caching behavior using ChannelsLiveServerTestCase. @@ -11,17 +15,13 @@ class ContentTypeCacheTestCase(ChannelsLiveServerTestCase): This test case includes two tests that both hit the same view endpoint which tests ContentType.get_for_model() behavior before and after clearing the cache. """ - - @classmethod - def setUpClass(cls): - super().setUpClass() + commands = { + "clear_contenttype_cache": clear_contenttype_cache + } def setUp(self): - """Set up before each test.""" - # Clear the cache before each test to ensure clean state - ContentType.objects.clear_cache() - self.addCleanup(ContentType.objects.clear_cache) super().setUp() + self.run_server_command("clear_contenttype_cache") def test_contenttype_cache_first(self): """