On Thu, Dec 18, 2008 at 12:52 AM, Chris Lasher <span dir="ltr">&lt;<a href="mailto:chris.lasher@gmail.com">chris.lasher@gmail.com</a>&gt;</span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="Ih2E3d">On Wed, Nov 12, 2008 at 3:58 PM, Kumar McMillan <span dir="ltr">&lt;<a href="mailto:kumar.mcmillan@gmail.com" target="_blank">kumar.mcmillan@gmail.com</a>&gt;</span> wrote:<br><div class="gmail_quote">
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
2. put all tests within your package. &nbsp;So if your package is<br>
foo/__init__.py you would have a directory like foo/tests/__init__.py,<br>
foo/tests/test_utils.py, etc. &nbsp;They will get deployed via python<br>
setup.py install<br>
</blockquote></div><br></div>What&#39;s the best way to import the module whose fixtures you want to test using this model, where your test module is in the tests/ subdirectory (pkg/tests/foo_tests.py), and the module is in the root directory (pkg/foo.py)? How do you put the the modules on sys.path for the tests, and make it work any way (e.g., if you&#39;re using setup.py to call out your tests)? Anyone care to point to code that uses this layout so we can get an example of how this is used in practice?<br>

</blockquote><div><br>Ah, perhaps I should have Googled it. I thought about it more and used Google Code search until I stumbled upon the MoinMoin unit tests: <a href="http://tinyurl.com/4hms5j">http://tinyurl.com/4hms5j</a><br>
<br>In there is a neat idiomatic snippet to ensure that the tests, which are in the subdirectory &quot;tests/&quot; can always import the modules above them in the root directory:<br><br>moinpath = os.path.join(os.path.dirname(sys.argv[0]), os.pardir)<br>
sys.path.insert(0, os.path.abspath(moinpath))<br><br>That&#39;s pretty clever, and works a treat! I&#39;m using this for my own projects.<br><br>Chris<br></div></div>