<br><br><div class="gmail_quote">On Wed, Apr 7, 2010 at 5:46 PM, Mark Roddy <span dir="ltr">&lt;<a href="mailto:markroddy@gmail.com">markroddy@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div><div></div><div class="h5">On Wed, Apr 7, 2010 at 5:11 PM, Alfredo Deza &lt;<a href="mailto:alfredodeza@gmail.com">alfredodeza@gmail.com</a>&gt; wrote:<br>
&gt; Hi,<br>
&gt; I am having some issues with the Nose importer.<br>
&gt; My project layout is set as follows:<br>
&gt; /project<br>
&gt; /project/lib<br>
&gt; /project/tests<br>
&gt; When I run &#39;nosetests -v&#39; in /project everything runs OK (tests import from<br>
&gt; within &#39;lib&#39;).<br>
&gt; But when I am within /project/tests &#39;nosetests -v&#39; fails with an ImportError<br>
&gt; exception saying it cannot import the<br>
&gt; files from lib on only *one* of the test files.<br>
&gt; However, if I take the same test file that is throwing exceptions and run it<br>
&gt; against nose, it completes the tests successfully:<br>
&gt; &#39;nosetests -v test_permissions.py&#39;<br>
&gt; It also works fine when calling it via python:<br>
&gt; &#39;python test_permissions.py&#39;<br>
&gt; The one file that test_permissions.py is trying to import but is failing is:<br>
&gt; &#39;permissions&#39;, and it does so by:<br>
&gt; sys.path.append(&#39;../&#39;)<br>
&gt; from lib import hg, permissions, upgrade<br>
&gt; I am not sure why it would be able to import &#39;hg&#39; and &#39;database&#39;, but fail<br>
&gt; to import &#39;permissions&#39;, and only when it runs all tests within the tests<br>
&gt; directory.<br>
&gt; Here is a copy of one of the exceptions:<br>
&gt; ======================================================================<br>
&gt; ERROR: Failure: ImportError (cannot import name permissions)<br>
&gt; ----------------------------------------------------------------------<br>
&gt; Traceback (most recent call last):<br>
&gt;   File &quot;/usr/local/lib/python2.6/dist-packages/nose/loader.py&quot;, line 382, in<br>
&gt; loadTestsFromName<br>
&gt;     addr.filename, addr.module)<br>
&gt;   File &quot;/usr/local/lib/python2.6/dist-packages/nose/importer.py&quot;, line 39,<br>
&gt; in importFromPath<br>
&gt;     return self.importFromDir(dir_path, fqname)<br>
&gt;   File &quot;/usr/local/lib/python2.6/dist-packages/nose/importer.py&quot;, line 86,<br>
&gt; in importFromDir<br>
&gt;     mod = load_module(part_fqname, fh, filename, desc)<br>
&gt;   File &quot;/home/alfredo/pacha/tests/test_permissions.py&quot;, line 10, in &lt;module&gt;<br>
&gt;     from lib import hg, permissions, database<br>
&gt; ImportError: cannot import name permissions<br>
&gt;<br>
&gt;<br>
&gt; Maybe I need to import differently? But then again... *why* it works when I<br>
&gt; call it directly? I basically want<br>
&gt; to be able to run from either /project or /project/tests with the same<br>
&gt; results.<br>
&gt;<br>
&gt;<br>
&gt; --<br>
&gt; Alfredo Deza<br>
&gt;<br>
&gt;<br>
</div></div>&gt; _______________________________________________<br>
&gt; testing-in-python mailing list<br>
&gt; <a href="mailto:testing-in-python@lists.idyll.org">testing-in-python@lists.idyll.org</a><br>
&gt; <a href="http://lists.idyll.org/listinfo/testing-in-python" target="_blank">http://lists.idyll.org/listinfo/testing-in-python</a><br>
&gt;<br>
&gt;<br>
<br>
One possibility for why you can import &#39;hg&#39; from lib but not<br>
&#39;permissions&#39; is that &#39;hg&#39; module that gets imported is not actually<br>
the one you expect (when running from the &#39;tests&#39; directory).  I ran<br>
into this the other day when I had my path messed up, and I could<br>
import one module from a package but not another.  Turns out the one I<br>
could import was under site-packages as I had an older version<br>
installed which did not have the module that the import failed on.<br></blockquote><div><br></div><div>This is not the case, since &#39;hg&#39; is not able to import at all from anywhere on the system.</div><div>The actual Mercurial package is called &#39;mercurial&#39;. </div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
You can check that the &#39;hg&#39; module which gets imported is actually the<br>
module you expect by looking at it&#39;s __file__ attribute.<br></blockquote><div><br></div><div>Yep, this verified that it is actually the one I have. </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<font color="#888888"><br>
-Mark<br>
</font></blockquote></div><br><br><div>I guess my solution will be to move the tests directory out of the standard location (root level) inside &#39;lib&#39;</div><div><br></div><div><br clear="all"><br>-- <br>Alfredo Deza<br>
<br>
</div>