From 37eb8909699d261b9b879e6f04dbfeec75b5e080 Mon Sep 17 00:00:00 2001 From: Carlton Gibson Date: Thu, 11 Dec 2025 10:05:51 +0100 Subject: Noted testing uses for ContentTypeManager.clear_cache() method. It is often necessary to reset the cache between tests, or after preparing test state, when using content types. Django's test suite already does this when needed, but users will need to do similar in their own tests. --- docs/ref/contrib/contenttypes.txt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'docs') diff --git a/docs/ref/contrib/contenttypes.txt b/docs/ref/contrib/contenttypes.txt index 9a6b14ef4c..961e454832 100644 --- a/docs/ref/contrib/contenttypes.txt +++ b/docs/ref/contrib/contenttypes.txt @@ -181,8 +181,16 @@ The ``ContentTypeManager`` :class:`~django.contrib.contenttypes.models.ContentType` to keep track of models for which it has created :class:`~django.contrib.contenttypes.models.ContentType` instances. You - probably won't ever need to call this method yourself; Django will call - it automatically when it's needed. + probably won't need to call this method in application code yourself; + Django will call it automatically when it's needed. + + You may need to clear the cache when testing, to reset between tests, + or after preparing test state. For example:: + + class ContentTypesTests(TestCase): + def setUp(self): + ContentType.objects.clear_cache() + self.addCleanup(ContentType.objects.clear_cache) .. method:: get_for_id(id) -- cgit v1.3