Running django runserver with coverage?
Answered
Hi,
I can "Run with coverage" my django runserver process, but when I stop it I never see any coverage information (not even a 'not covered' next to things, and there is no report in the "Show code coverage data" window.
I'm guessing this is because I'm stopping it rather than letting it terminate naturally... but runserver never terminates on its own.
Is there a neat way to execute my runserver process with coverage?
Thanks
Please sign in to leave a comment.
Most likely the issue is that Django runs two processes by default (one to watch for changed files and another to actually process requests), and the coverage information is only gathered from the first process. Please try running Django with --no-reload enabled.
Dmitry: thanks for your suggestion, I have enabled --noreload but there is no change in behaviour.
I have also tried enabling 'use builtin coverage.py' with no effect (my coverage version is coverage==3.5.1)
I'm running into this issue too, using Professional Edition 2018.2.4. I have set the "No reload" checkbox in the Django run dialog, and the corresponding command logged by PyCharm looks like this:
========
/usr/bin/python3.6 /main/.../manage.py runserver --noreload 0.0.0.0:8000
Performing system checks...
System check identified no issues (0 silenced).
October 24, 2018 - 16:23:19
Django version 2.0.5, using settings 'testdjango.settings'
========
I then run my tests, and stop Django. However, the "Tools->Show Coverage Data" menu is always empty. I'm using the built-in Coverage option. Note that I have the debugger speed up installed, and also this environment variable for another issue: "PYDEVD_USE_FRAME_EVAL=NO".
Is there some other setting that can be interfering with this?
Hi Srhaque,
Please attach a screenshot with your Run/Debug configuration.
Is it possible to upload a sample project and idea.log (Help | Show Log in...) to https://uploads.services.jetbrains.com/ zipped?
If yes, please do so and let me know the name of the zip file.
Hi Sergey,
Here is the screenshot as requested:
I will try to create a sample project for you later; I'll advise when that is available.
Thanks!
The typical usecase is to run tests with coverage with no need to use server.
Could you please try it?
Could you please also try to run it in the terminal to see if it works? Maybe we missed something.
That's not possible in my case as I am using Selenium based tests (mostly; I also have a few based on WebTest, whose coverage I am not concerned with here). I can run the test interactively like this:
=====
$ coverage run manage.py runserver --noreload 0.0.0.0:8000
=====
and then I run my test script in another window. At the end, I terminate Django using ^C, and this produces the expecte coverage output.
I see, thanks for clarification!
We have filed an issue to our issue tracker https://youtrack.jetbrains.com/issue/PY-32417, please vote for it and follow for future updates. See https://intellij-support.jetbrains.com/hc/en-us/articles/207241135-How-to-follow-YouTrack-issues-and-receive-notifications if you are not familiar with YouTrack.
The possible workaround is also described in the issue.
Thanks!