How does pytest find files to test?
<p>I know how py.test discovers tests to run, but I don't know how to make the tests refer to the files that contains the code to test.</p>

<p>My project looks like this:</p>

<pre><code>arith.py
tests/
    test_airth.py
</code></pre>

<p>In my project root directory, I have the file <code>arith.py</code> with</p>

<pre><code>def plus(x, y):
    return x + y
</code></pre>

<p>In the file <code>tests/test_arith.py</code> I have</p>

<pre><code>import arith
def test_plus():
    assert arith.plus(3, 5) == 8
</code></pre>

<p>When I run, in the project root directory,</p>

<pre><code>pytest
</code></pre>

<p>It discovers my test file, because I followed the test discovery rules. But pytest replies with</p>

<blockquote>
  <p>ImportError while importing test module tests/test_arith.py'</p>
</blockquote>

<p>I ran <code>pytest</code> from the project root, so why does it not like my import? It wants to find the files that I am testing in the <code>tests</code> directory!</p>

<p>How can I set up the imports properly, so that my test files in the <code>tests/</code> directory, can see the files under test which are in the project root directory? (The examples in pytest's documentation seem to not do anything special...perhaps the tests are in the same directory as the files under test? They describe test discovery in great detail, but I must have missed how to set up the tests so they can see the code they are testing.)</p>