Skip to content

ChannelsLiveServerTestCase keeps old ContentType cache between tests #2208

@johanneswilm

Description

@johanneswilm

When running multiple ChannelsLiveServerTestCase tests, the id values of the contenttypes change between test runs, yet the cache is not emptied. So ContentType.get_for_model(X) will get the instance from a previous test.

The only work-around I found was to add the following within the django view itself:

if 'test' in sys.argv:
            ContentType.objects.clear_cache()

It is not enough to add this in the setUp or tearDown methods of the test, as the test runs in a separate thread and therefore has a separate cache. If someone can tell me how to, I'd very much like to move this to to the test code.

Tested with Django 5.2.9 and Django Channels 4.3.2.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions