title: Running pytest with cython - how to compile cython modules in pytest?
body: <p>I have a project organized as follows:</p>
  
  <pre><code>project
  ├── project
  │   ├── module1
  │   │   ├── api.py
  │   │   ├── _cpython_foo.py
  │   │   └── _cython_foo.pyx
  │   └── module2
  ├── setup.py
  └── tests
      └── module1
          ├── test_cython_foo.py
          └── test_cpython_foo.py
  </code></pre>
  
  <p>where <code>api.py</code> imports cythonized extensions:</p>
  
  <pre><code> """api.py""""
   from _cython_foo import cython_fun
  </code></pre>
  
  <p>My setup script builds the <code>.pyx</code> source inplace correctly and I'm able to use <code>cython_fun</code> in the installed package:</p>
  
  <pre><code>import project.module1.api as module1
  module1.cython_fun()    # OK
  </code></pre>
  
  <p>However, <code>pytest</code> complains that it cannot import the cython module since the compiled binaries are not in place until I invoke setup.</p>
  
  <pre><code>project/module1/api.py:2: in &lt;module&gt;
      from _cython_foo import cython_fun
  E   ImportError: No module named _cython_foo
  </code></pre>
  
  <p>It seems like bad style to leave a bunch of precompiled binaries inside my project directory that pytest depends on, so is there a conventional way to have pytest temporarily build the cython modules for the purpose of my unit tests only?</p>