[TIP] Coverage for the Django server

Shaheed Haque shaheedhaque at gmail.com
Fri Apr 26 13:37:38 PDT 2019


Apologies for the bump, but I'm really stuck for what to try next.

P.S. I did also email the Django list, but that was similarly quiet
<https://groups.google.com/d/msg/django-users/_kYGSeDQG0Q/FUlYshV_CAAJ>.


On Tue, 16 Apr 2019 at 12:03, Shaheed Haque <shaheedhaque at gmail.com> wrote:

> Hi,
>
> I'm trying to get coverage.py to generate results for code running
> under the Django server [1]. I expected that the initial difficulty
> would be with having the server exit in a manner which allowed the
> end-of-run coverage logic to get a chance to run. I hacked a solution
> to that [2], and I can now say
>
> $ coverage -p manage.py runserver ...
>
> and see a .coverage.xxx.yyy file created. Viewing the results of
> "coverage combine" in pycharm shows that the static parts of the code
> (e.g. class and function definitions) are covered, but none of the
> function bodies are covered! For example, in this fragment, the first
> 2 lines are green, but the third is red:
>
>     class CreateForm(forms.ModelForm):
>         def __init__(self, *args, **kwargs):
>             super().__init__(*args, **kwargs)
>
> Though I could be mistaken, AFAIK, Django does not use any of the
> constructs which are known sources of incompatibility. I also note
> that most references to using Django with coverage refer to running
> tests using Django's built-in test infrastructure ("python3 manage.py
> test --with-coverage") but like a recent thread on this list, I am
> running the tests separately (though in my case, they are Python
> Selenium based tests running under pytest).
>
> From coverage.py's point of view, isn't Django just a normal Python
> server program? What might I be doing wrong? Any clues much
> appreciated.
>
> Thanks, Shaheed
>
> [1] My wider setup includes code running under Celery and so on, but I
> realise that has its own limitations with regard to coverage.py
> compatibility.
> [2] See https://groups.google.com/forum/#!topic/django-users/_kYGSeDQG0Q
> if needed.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20190426/955229f4/attachment.htm>


More information about the testing-in-python mailing list