<br><br><div class="gmail_quote">On Fri, Nov 25, 2011 at 6:00 AM, Michael Foord <span dir="ltr">&lt;<a href="mailto:michael@voidspace.org.uk">michael@voidspace.org.uk</a>&gt;</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 class="h5">
    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 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 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><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&#39;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(&#39;sqlalchemy.url&#39;)</div><div>    echo = settings.get(&#39;sqlalchemy.echo&#39;)</div><div><br></div><div>    print &#39;Creating the tables on the test database %s&#39; % 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>