Is there a standard way to tell py.test to run against specific code?
<p>I'm trying to run a Python project's unit tests using py.test.  Until recently I've used nose and it ran the tests against my local source code instead of the installed package, but py.test seems to want to run against the installed package, meaning I have to run <code>python setup.py install</code> before every test run.</p>

<p>The project is organized like so:</p>

<pre><code>/project
    /project  
        __init__.py
        project_file.py
    /test
        __init__.py
        /test_project
            test_project_file.py
</code></pre>

<p>The only way I've found to get py.test to run against the local code is to run <code>python -m pytest</code> in the top /project folder.  It's very strange, as running <code>py.test</code> in the same location runs against the installed code.  According to <a href="http://doc.pytest.org/en/latest/usage.html#cmdline" rel="nofollow">the docs</a> these commands ought to be equivalent, and --version returns the same info for both.</p>

<p>Is there a standard way to tell py.test to run against specific code?  I haven't been able to find a clear answer in py.test's documentation.</p>

<p>My first mistake was setting up my project using <code>python setup.py install</code> instead of <code>python setup.py develop</code>.  Pytest expects you to use the latter, which seems like good practice anyway.</p>

<p>If it's necessary to run against local code when the same code is installed, there does seem to be a way to do it.  <a href="http://stackoverflow.com/a/34520971/2626755">This SO post</a> mentions a "hidden feature" of pytest, where you can put a conftest.py file in your root directory to tell pytest to run using your local code.  Pytest seems to use the location of your overall configuration file to determine what it thinks your root directory is.  This file is pytest.ini in my case.</p>

<p>As a curiosity, I believe that <code>python -m pytest</code> running using the local code where <code>py.test</code> did not was due to Python's default behavior of adding the directory that it's called in to sys.path.</p>

python python-2.7 unit-testing testing py.test