<br><br><div class="gmail_quote">On Wed, Apr 7, 2010 at 5:46 PM, Mark Roddy <span dir="ltr"><<a href="mailto:markroddy@gmail.com">markroddy@gmail.com</a>></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 <<a href="mailto:alfredodeza@gmail.com">alfredodeza@gmail.com</a>> wrote:<br>
> Hi,<br>
> I am having some issues with the Nose importer.<br>
> My project layout is set as follows:<br>
> /project<br>
> /project/lib<br>
> /project/tests<br>
> When I run 'nosetests -v' in /project everything runs OK (tests import from<br>
> within 'lib').<br>
> But when I am within /project/tests 'nosetests -v' fails with an ImportError<br>
> exception saying it cannot import the<br>
> files from lib on only *one* of the test files.<br>
> However, if I take the same test file that is throwing exceptions and run it<br>
> against nose, it completes the tests successfully:<br>
> 'nosetests -v test_permissions.py'<br>
> It also works fine when calling it via python:<br>
> 'python test_permissions.py'<br>
> The one file that test_permissions.py is trying to import but is failing is:<br>
> 'permissions', and it does so by:<br>
> sys.path.append('../')<br>
> from lib import hg, permissions, upgrade<br>
> I am not sure why it would be able to import 'hg' and 'database', but fail<br>
> to import 'permissions', and only when it runs all tests within the tests<br>
> directory.<br>
> Here is a copy of one of the exceptions:<br>
> ======================================================================<br>
> ERROR: Failure: ImportError (cannot import name permissions)<br>
> ----------------------------------------------------------------------<br>
> Traceback (most recent call last):<br>
> File "/usr/local/lib/python2.6/dist-packages/nose/loader.py", line 382, in<br>
> loadTestsFromName<br>
> addr.filename, addr.module)<br>
> File "/usr/local/lib/python2.6/dist-packages/nose/importer.py", line 39,<br>
> in importFromPath<br>
> return self.importFromDir(dir_path, fqname)<br>
> File "/usr/local/lib/python2.6/dist-packages/nose/importer.py", line 86,<br>
> in importFromDir<br>
> mod = load_module(part_fqname, fh, filename, desc)<br>
> File "/home/alfredo/pacha/tests/test_permissions.py", line 10, in <module><br>
> from lib import hg, permissions, database<br>
> ImportError: cannot import name permissions<br>
><br>
><br>
> Maybe I need to import differently? But then again... *why* it works when I<br>
> call it directly? I basically want<br>
> to be able to run from either /project or /project/tests with the same<br>
> results.<br>
><br>
><br>
> --<br>
> Alfredo Deza<br>
><br>
><br>
</div></div>> _______________________________________________<br>
> testing-in-python mailing list<br>
> <a href="mailto:testing-in-python@lists.idyll.org">testing-in-python@lists.idyll.org</a><br>
> <a href="http://lists.idyll.org/listinfo/testing-in-python" target="_blank">http://lists.idyll.org/listinfo/testing-in-python</a><br>
><br>
><br>
<br>
One possibility for why you can import 'hg' from lib but not<br>
'permissions' is that 'hg' module that gets imported is not actually<br>
the one you expect (when running from the 'tests' 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 'hg' is not able to import at all from anywhere on the system.</div><div>The actual Mercurial package is called 'mercurial'. </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 'hg' module which gets imported is actually the<br>
module you expect by looking at it'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 'lib'</div><div><br></div><div><br clear="all"><br>-- <br>Alfredo Deza<br>
<br>
</div>