<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
On 25/11/2011 12:22, Alfredo Deza wrote:
<blockquote
cite="mid:CAK7CpVEay9nM3eWZruiADJ5G-4+ZxY=7N9GPvo6w4fYQ+KwyRA@mail.gmail.com"
type="cite"><br>
<br>
<div class="gmail_quote">On Fri, Nov 25, 2011 at 7:07 AM, John
Anderson <span dir="ltr"><<a moz-do-not-send="true"
href="mailto:sontek@gmail.com">sontek@gmail.com</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex;">
<br>
<br>
<div class="gmail_quote">
<div class="im">On Fri, Nov 25, 2011 at 6:00 AM, Michael
Foord <span dir="ltr"><<a moz-do-not-send="true"
href="mailto:michael@voidspace.org.uk" target="_blank">michael@voidspace.org.uk</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
<div text="#000000" bgcolor="#FFFFFF">
<div>
<div> On 25/11/2011 11:55, John Anderson wrote:
<blockquote type="cite">I have a base class that
all my models inherit from:
<div><br>
</div>
<div><a moz-do-not-send="true"
href="http://paste2.org/p/1796621"
target="_blank">http://paste2.org/p/1796621</a></div>
<div><br>
</div>
<div>and majority of my tests are touching
models and I even have tests against this
specific class:</div>
<div><br>
</div>
<div><a moz-do-not-send="true"
href="http://paste2.org/p/1796622"
target="_blank">http://paste2.org/p/1796622</a></div>
<div><br>
</div>
<div>Yet, when I run a coverage test in py.test:</div>
<div>py.test --cov-report=term-missing --cov
app/models.py</div>
<div><br>
</div>
<div>
<div>app/models 46 23 50% 1-27,
37-40, 59, 65, 76, 82-84</div>
</div>
<div><br>
</div>
<div><br>
</div>
<div>How are lines 1-27 not covered?</div>
</blockquote>
<br>
</div>
</div>
All of those lines (imports, class definition,
decorator application) are executed at *import time*
(i.e. when the module is first created). The fact that
those lines are reported as not covered implies to me
that you are starting the test run (and therefore
importing your models) before coverage is started.<br>
<br>
You need to run your tests under the coverage tool, or
ensure that coverage tracing is started before any
imports execute.<br>
<br>
</div>
</blockquote>
</div>
<div>
<div><br>
</div>
<div>Ahh, So I have some py.test configuration, so that a
test database is set to a clean slate when I start my
tests, I thought pytest_configure would be late enough,
but I guess its not? This is what i'm doing:</div>
<div><br>
</div>
<div>from test_settings import settings</div>
<div>from pyramid.config import Configurator</div>
<div>from app.models import register_models</div>
<div>from app.models import Entity</div>
<div><br>
</div>
<div><br>
</div>
<div>def pytest_configure():</div>
<div> url = settings.get('sqlalchemy.url')</div>
<div> echo = settings.get('sqlalchemy.echo')</div>
<div><br>
</div>
<div> print 'Creating the tables on the test database
%s' % url</div>
<div><br>
</div>
<div> config = Configurator(settings=settings)</div>
<div><br>
</div>
<div> register_models(config)</div>
<div><br>
</div>
<div> Entity.setup_database(url, echo=echo, drop=True,
create=True)</div>
</div>
</div>
</blockquote>
<div><br>
</div>
<div>Hi John, </div>
<div><br>
</div>
<div>This is a similar problem that the Pecan [0] framework had
(still?) for exposing configuration setup for the actual
application</div>
<div>at test time.</div>
<div><br>
</div>
<div>The problem is (as you suspect) that the configuration in
pytest_configure happens *before* any of the mechanisms for
coverage start.</div>
</div>
</blockquote>
<br>
It is worth filing an issue against py.test. It may be possible to
fix in future versions so that coverage tracing starts before
configuration is done.<br>
<br>
All the best,<br>
<br>
Michael Foord<br>
<br>
<blockquote
cite="mid:CAK7CpVEay9nM3eWZruiADJ5G-4+ZxY=7N9GPvo6w4fYQ+KwyRA@mail.gmail.com"
type="cite">
<div class="gmail_quote">
<div><br>
</div>
<div>My suggestion would be not to use this and to try and have
a base class that you can use for your tests that include this
configuration and</div>
<div>database setup. </div>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex;">
<br>
_______________________________________________<br>
testing-in-python mailing list<br>
<a moz-do-not-send="true"
href="mailto:testing-in-python@lists.idyll.org">testing-in-python@lists.idyll.org</a><br>
<a moz-do-not-send="true"
href="http://lists.idyll.org/listinfo/testing-in-python"
target="_blank">http://lists.idyll.org/listinfo/testing-in-python</a><br>
<br>
</blockquote>
</div>
<br>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
testing-in-python mailing list
<a class="moz-txt-link-abbreviated" href="mailto:testing-in-python@lists.idyll.org">testing-in-python@lists.idyll.org</a>
<a class="moz-txt-link-freetext" href="http://lists.idyll.org/listinfo/testing-in-python">http://lists.idyll.org/listinfo/testing-in-python</a>
</pre>
</blockquote>
<br>
<br>
<pre class="moz-signature" cols="72">--
<a class="moz-txt-link-freetext" href="http://www.voidspace.org.uk/">http://www.voidspace.org.uk/</a>
May you do good and not evil
May you find forgiveness for yourself and forgive others
May you share freely, never taking more than you give.
-- the sqlite blessing <a class="moz-txt-link-freetext" href="http://www.sqlite.org/different.html">http://www.sqlite.org/different.html</a>
</pre>
</body>
</html>