<html><head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type">
</head><body bgcolor="#FFFFFF" text="#000000">Shaeed, did you try this? 
It looks like you might have to edit manage.py?<br>
<br>
<a class="moz-txt-link-freetext" href="https://stackoverflow.com/questions/24668174/how-to-test-coverage-properly-with-django-nose">https://stackoverflow.com/questions/24668174/how-to-test-coverage-properly-with-django-nose</a><br>
<br>
I'm pretty sure we were using coverage in one of my previous jobs, but 
my memory of the details is fuzzy now. I may be able to put you in touch
 with one of my former coworkers who might be able to help, if you're 
still stuck. <br>
<br>
Sam<br>
<br>
<br>
<span><a class="moz-txt-link-abbreviated" href="mailto:testing-in-python-request@lists.idyll.org">testing-in-python-request@lists.idyll.org</a> wrote:</span><br>
<blockquote 
cite="mid:mailman.1.1556391602.13948.testing-in-python@lists.idyll.org" 
type="cite">
  <pre wrap="">Send testing-in-python mailing list submissions to
        <a class="moz-txt-link-abbreviated" href="mailto:testing-in-python@lists.idyll.org">testing-in-python@lists.idyll.org</a>

To subscribe or unsubscribe via the World Wide Web, visit
        <a class="moz-txt-link-freetext" href="http://lists.idyll.org/listinfo/testing-in-python">http://lists.idyll.org/listinfo/testing-in-python</a>
or, via email, send a message with subject or body 'help' to
        <a class="moz-txt-link-abbreviated" href="mailto:testing-in-python-request@lists.idyll.org">testing-in-python-request@lists.idyll.org</a>

You can reach the person managing the list at
        <a class="moz-txt-link-abbreviated" href="mailto:testing-in-python-owner@lists.idyll.org">testing-in-python-owner@lists.idyll.org</a>

When replying, please edit your Subject line so it is more specific
than "Re: Contents of testing-in-python digest..."


Today's Topics:

   1. Re: Coverage for the Django server (Shaheed Haque)
   2. Re: Coverage for the Django server (Marius Gedminas)
   3. Re: Coverage for the Django server (Shaheed Haque)


----------------------------------------------------------------------

Message: 1
Date: Fri, 26 Apr 2019 21:37:38 +0100
From: Shaheed Haque <a class="moz-txt-link-rfc2396E" href="mailto:shaheedhaque@gmail.com">&lt;shaheedhaque@gmail.com&gt;</a>
Subject: Re: [TIP] Coverage for the Django server
To: <a class="moz-txt-link-abbreviated" href="mailto:testing-in-python@lists.idyll.org">testing-in-python@lists.idyll.org</a>
Message-ID:
        <a class="moz-txt-link-rfc2396E" href="mailto:CAHAc2jdTfO5t6A1mBriq-Nk1XJeECsr_2pmq3NYVd_a53YyOOQ@mail.gmail.com">&lt;CAHAc2jdTfO5t6A1mBriq-Nk1XJeECsr_2pmq3NYVd_a53YyOOQ@mail.gmail.com&gt;</a>
Content-Type: text/plain; charset="utf-8"

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
<a class="moz-txt-link-rfc2396E" href="https://groups.google.com/d/msg/django-users/_kYGSeDQG0Q/FUlYshV_CAAJ">&lt;https://groups.google.com/d/msg/django-users/_kYGSeDQG0Q/FUlYshV_CAAJ&gt;</a>.


On Tue, 16 Apr 2019 at 12:03, Shaheed Haque <a class="moz-txt-link-rfc2396E" href="mailto:shaheedhaque@gmail.com">&lt;shaheedhaque@gmail.com&gt;</a> wrote:

</pre>
  <blockquote type="cite"><pre wrap="">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 <a class="moz-txt-link-freetext" href="https://groups.google.com/forum/#!topic/django-users/_kYGSeDQG0Q">https://groups.google.com/forum/#!topic/django-users/_kYGSeDQG0Q</a>
if needed.

</pre></blockquote>
  <pre wrap=""><!---->-------------- next part --------------
An HTML attachment was scrubbed...
URL: <a class="moz-txt-link-rfc2396E" href="http://lists.idyll.org/pipermail/testing-in-python/attachments/20190426/955229f4/attachment.html">&lt;http://lists.idyll.org/pipermail/testing-in-python/attachments/20190426/955229f4/attachment.html&gt;</a>

------------------------------

Message: 2
Date: Sat, 27 Apr 2019 09:57:16 +0300
From: Marius Gedminas <a class="moz-txt-link-rfc2396E" href="mailto:marius@gedmin.as">&lt;marius@gedmin.as&gt;</a>
Subject: Re: [TIP] Coverage for the Django server
To: Shaheed Haque <a class="moz-txt-link-rfc2396E" href="mailto:shaheedhaque@gmail.com">&lt;shaheedhaque@gmail.com&gt;</a>
Cc: <a class="moz-txt-link-abbreviated" href="mailto:testing-in-python@lists.idyll.org">testing-in-python@lists.idyll.org</a>
Message-ID: &lt;20190427065716.ql27aq6kyv7ztpvb@platonas&gt;
Content-Type: text/plain; charset=us-ascii

Um, I sent a reply to this on Apr 16.  Did it get stuck in some
moderation queue?  Are my PGP signatures at fault?

On Fri, Apr 26, 2019 at 09:37:38PM +0100, Shaheed Haque wrote:
</pre>
  <blockquote type="cite"><pre wrap="">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 [1]similarly quiet.


On Tue, 16 Apr 2019 at 12:03, Shaheed Haque <a class="moz-txt-link-rfc2396E" href="mailto:[2]shaheedhaque@gmail.com">&lt;[2]shaheedhaque@gmail.com&gt;</a> 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 ...
</pre></blockquote>
  <pre wrap=""><!---->
TL;DR is try passing --noreload to runserver.

</pre>
  <blockquote type="cite"><pre wrap="">    Though I could be mistaken, AFAIK, Django does not use any of the
    constructs which are known sources of incompatibility. 
</pre></blockquote>
  <pre wrap=""><!---->
It does: the Django autoreloader spawns a subprocess to run the actual
view code (that gets killed and restarted every time the autoreloader
detects source code changes).

Marius Gedminas
</pre>
</blockquote>
<br>
</body></html>