Unit-testing a boost::python library in python
<p>So I have a shared library created with boost::python (C++). 
For the C++ functions inside I have unit-tests that check that they are working.
Now I would like to use unit-test to see if I implemented the python interface correctly.
For this I thought about using using the python package <code>unittest</code>.</p>

<p>Now my Folder setup is roughly:</p>

<pre><code>project
  |
   -- C++ source (library and boost::python stuff)
  |
   -- build (here the shared library is located)
  |
   -- Test (here I have the python classes that should test the interface)
</code></pre>

<p>The test folder has some subfolders that mirror the structure of the python interface, containing lots of small python modules testing the different aspects of the library.</p>

<p>So the <strong>question</strong> now:</p>

<blockquote>
  <p>How do I <code>import</code> the shared library into the test?</p>
</blockquote>

<p>What I tried so far was in my <code>test_main.py</code></p>

<pre><code>import sys
sys.path.insert(0,'../build')
</code></pre>

<p>But this does not help for the modules inside the test folder. And anyways hardcoding this path into the test-code seems to be hackish. I also don't want to install an untested library just to figure out the tests failed to then uninstall it again.</p>

<p>What you could do is run the tests while you are in the root directory in your case <code>project</code>. You can do <code>python Test/test_name.py</code>. Make sure your build library has a <code>__init__.py</code> file</p>

<p>The only change to the test is you'd have</p>

<pre><code>from build import blah #blah is the component you testing
#test code here
</code></pre>

python c++ unit-testing boost out-of-source