Stubborn contenttypes failures

Resuming work fully

After two weeks of constant assignments and online exams, I have finally largely finished most of my university coursework so I can resume complete work on Django.

Back to tackling contenttypes_tests, I initially had no idea at all what was going wrong when I read the test earlier this week.

So I did what I’ve always done when I see code I do not understand at all and I started messing with things to get a feel for how it works. Eventually, I ventured a guess there was an issue with the modify_settings decorator since removing it in one test almost fixed it (but removing it in the other one actually breaks it). After tracing through it, my guess was wrong and the only remaining culprit was the command call itself.

Bingo

The command has a nice python generator:

to_remove = [ct for ct in content_types if ct.model_class() is None]

This checked if the ContentType’s model has ceased to exist or not. When running this generator with spawned processes on the full test suite, the app registry does not properly register models making some models disappear from their ContentTypes. This is an issue in my opinion with improper test isolation: ContentTypes from other test apps are causing this issue, so finding a way to properly isolate them would fix it.

To be frank, I couldn’t find a workaround that fixed the fundamental issue with the app registry. The less elegant hack I developed was to delete all ContentTypes before each test is run; this fixes the issue by ensuring the ContentTypes that are created during the tests are the only ones that count and I think it creates a form of test isolation.