I should know the answer to this, but I don't: if you try to measure the coverage of a Django project like this:
coverage run manage.py runserver
you get coverage measurement that misses all of your actual code. Something early on in the process is stopping the measurement, or all the real work happens in a new context that doesn't get measured at all.
Can someone point me to the specific point in the process where the measurement breaks down, so that I can try to fix coverage.py so that it will measure it properly the way people expect?
Do you get the same problem if you run as follows?
Without
--noreload
, another process is started behind the scenes. One process runs the server, the other looks for code changes and restarts the server when changes are made. The chances are, you're doing the coverage run on the monitoring process rather than the serving process.Look at
django/core/management/commands/runserver.py
anddjango/utils/autoreload.py
.Update: I ran the coverage command, then used
ps
andlsof
to look at what was happening. Here's what I observed:IOW, even before any reloading there are two processes, and the one listening on the TCP port is not the one which coverage is running on.
Here's what I see with
--noreload
:So it's not obvious why coverage wouldn't work in the
--noreload
case. In my very brief test with--noreload
, I got coverage of my view code, as shown by the following extract: