INSTALLED_APPS. It was. It worked fine through the browser, and the test code looked good. What was worse, it was working when I last ran it before the weekend. Why did it suddenly stop running?
I got my answer after some digging around in the Django source. It appears that you must have
models.pyin the app for tests to run. It so happened that this app has no models, only some views that do some calculations. Since
models.pywas empty, I had deleted it and didn't think too much about it. Whoops! The tests stopped running.
Once I had that figured out, the solution was simple - recreate the empty
models.py, and the tests started running again.
This whole thing is really unintuitive though. Who would have thought that removing an empty file would cause the tests to stop running? There doesn't seem to be any connection between them at all.
In a broader sense, any piece of code that uses
django.db.models.get_appsto get a list of installed apps is likely to run into this problem. Don't be surprised if you remove an empty
models.pyand then something breaks and you are left scratching your head as to what exactly happened.
This is exactly the kind of unintuitive "magic" that we Pythonistas hate :) Explicit is better than implicit etc.
What I don't understand is that the list of installed apps *IS* explicit. It's sitting there called
settings.py. Why does Django go about hunting through the models when it could just read this value? Any clues?