<div dir="ltr"><div dir="ltr">On Sat, 27 Apr 2019 at 15:08, Shaheed Haque &lt;<a href="mailto:shaheedhaque@gmail.com">shaheedhaque@gmail.com</a>&gt; wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, 27 Apr 2019 at 07:57, Marius Gedminas &lt;<a href="mailto:marius@gedmin.as" target="_blank">marius@gedmin.as</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Um, I sent a reply to this on Apr 16.  Did it get stuck in some<br>
moderation queue?  Are my PGP signatures at fault?<br>
<br>
On Fri, Apr 26, 2019 at 09:37:38PM +0100, Shaheed Haque wrote:<br>
&gt; Apologies for the bump, but I&#39;m really stuck for what to try next.<br>
&gt; <br>
&gt; P.S. I did also email the Django list, but that was [1]similarly quiet.<br>
&gt; <br>
&gt; <br>
&gt; On Tue, 16 Apr 2019 at 12:03, Shaheed Haque &lt;[2]<a href="mailto:shaheedhaque@gmail.com" target="_blank">shaheedhaque@gmail.com</a>&gt; wrote:<br>
&gt; <br>
&gt;     Hi,<br>
&gt; <br>
&gt;     I&#39;m trying to get coverage.py to generate results for code running<br>
&gt;     under the Django server [1]. I expected that the initial difficulty<br>
&gt;     would be with having the server exit in a manner which allowed the<br>
&gt;     end-of-run coverage logic to get a chance to run. I hacked a solution<br>
&gt;     to that [2], and I can now say<br>
&gt; <br>
&gt;     $ coverage -p manage.py runserver ...<br>
<br>
TL;DR is try passing --noreload to runserver.<br></blockquote></div></div></blockquote><div><br></div><div><div dir="ltr">I finally got back to this, and confirmed that having definitely tried with --noreload I still get coverage &quot;green&quot; only for the static parts of the code (i.e. class definitions and the like), while coverage of actual executable code inside methods/functions is completely missing (&quot;red&quot;).</div><div><br></div><div>To be explicit, I ran django like this (i.e. as an argument to a subprocess call):</div><div><br></div><div>    [&#39;coverage&#39;, &#39;run&#39;, &#39;-p&#39;, &#39;manage.py&#39;, &#39;runserver&#39;, &#39;--noreload&#39;, &#39;<a href="http://0.0.0.0:8000">0.0.0.0:8000</a>&#39;]</div><div><br></div>and the end-of-run signal to the server process to exit ends up calling:</div><div><span style="font-family:monospace"><span style="color:rgb(0,0,0)"><br></span></span></div><div><span style="font-family:monospace"><span style="color:rgb(0,0,0)">    import _thread</span><br>
</span><span style="font-family:monospace"><span style="color:rgb(0,0,0)">    _thread.interrupt_main()</span><br>
<br></span></div><div>(this being the recipie that Google came up with for exiting Django), which ends up dumping a file with a name like <br></div><div><br></div><div>    <span style="color:rgb(0,0,0);font-family:monospace">.coverage.&lt;hostname&gt;.8318.928006</span></div><span style="font-family:monospace">
<br></span><div>I then run &quot;coverage combine&quot; and view the results in PyCharm (hence the red and green colours). </div><div><br></div><div>Perhaps the manner of the exit is the problem? Is there a way to get the coverage object needed to call the stop() and save() API methods?</div><div><br></div><div>Thanks, Shaheed </div><div><div class="gmail_quote"> <br></div></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
&gt;     Though I could be mistaken, AFAIK, Django does not use any of the<br>
&gt;     constructs which are known sources of incompatibility. <br>
<br>
It does: the Django autoreloader spawns a subprocess to run the actual<br>
view code (that gets killed and restarted every time the autoreloader<br>
detects source code changes).<br></blockquote><div><br></div><div>Wow. Thanks for the hint, I&#39;ll give it a try!<br></div><div> </div><div>Shaheed<br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">

Marius Gedminas<br>
-- <br>
I doubt, therefore I might be.<br>
</blockquote></div></div>
</blockquote></div></div>