ImportError running 'test' on namespace package - other package in namespace not found
I've got two projects: mynamespace.myprojectA and mynamespace.myprojectB myprojectB depends on myprojectA. I'm using setuptools 0.6c8 to manage both projects. Both projects are registered using 'setup develop'. Both projects are accessible from an interactive interpreter: PS C:\Users\me\projects> python Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information.
import mynamespace.myprojectA import mynamespace.myprojectB from mynamespace.myprojectA import mymoduleZ
However, when I run 'setup test' in myprojectB, the tests fail with File ".mymoduleZ.py", line NNN, in [some context] from mynamespace.myprojectA.mymoduleZ import MyClassC ImportError: No module named myprojectA.mymoduleZ In setup.py, the test_suite is nose.collector. I searched and couldn't find anyone else with this problem. Is this a supported configuration? Is there something I can do to make tests work with interdependent projects with the same root namespace? If there's not something obvious I should be doing differently, I'm happy to put together a minimal test case that reproduces the problem. Any suggestions are appreciated. Sincerely, Jason R. Coombs
Okay. I narrowed the problem down and created a minimal test case. I created two projects, myns.projA and myns.projB. myns.projA is stock basic_namespace project with one module added. First, I created myns.projA with the basic_namespace template from ZopeSkel:
paster create -t basic_namespace Selected and implied templates: zopeskel#basic_namespace A project with a namespace package
cat > myns.projA\myns\projA\modA.py def funcA():
Enter project name: myns.projA Variables: egg: myns.projA package: mynsproja project: myns.projA Enter namespace_package (Namespace package (like plone)) ['plone']: myns Enter package (The package contained namespace package (like example)) ['example']: projA ... (rest are defaults) Then I added a single module with a simple function print "funcA called" ^D myns.projB is another project created basically the same way, but they key to getting the bug to surface was to put the packages in a sub-directory... so I modified setup.py with the following parameters to setup: packages=find_packages('src'), package_dir={'': 'src'}, test_suite='nose.collector', And of course, I moved the myns directory to src/myns. Note, this only had to happen for myns.projB. Finally, I created a test directory and a file testBasic.py
cat > test/testBasic.py from myns.projA.modA import funcA ^D
Note, I could add a dependency from myns.projB on myns.projA, but it's not necessary for this demonstration. Then, I either setup myns.projA with either "install" or "develop" so that it's visible to the Python installation. Thereafter, if I try to run "setup.py test" on myns.projB, I get the ImportError. See error.txt, attached, for the transcript. I've also attached the two test packages as described. I notice now that the error appears to only occur when nose.collector is used... and when the package_dir of the child package is overridden. Perhaps this needs to go to the nose project and instead of the distutils project. Please advise on what I might do next to help resolve this issue. Obviously I could restructure my projects to avoid the problem, but I would much rather help resolve the problem, as I suspect it may affect other users' deployments as well. Much obliged, Jason -----Original Message----- From: Phillip J. Eby [mailto:pje@telecommunity.com] Sent: Friday, 20 June, 2008 08:46 To: Jason R. Coombs; distutils-sig@python.org Subject: Re: [Distutils] ImportError running 'test' on namespace package - other package in namespace not found At 08:07 PM 6/18/2008 -0600, Jason R. Coombs wrote:
If there's not something obvious I should be doing differently, I'm happy to put together a minimal test case that reproduces the problem.
Please do. Thanks!
At 06:06 PM 6/29/2008 -0600, Jason R. Coombs wrote:
Note, I could add a dependency from myns.projB on myns.projA, but it's not necessary for this demonstration.
Then, I either setup myns.projA with either "install" or "develop" so that it's visible to the Python installation.
Thereafter, if I try to run "setup.py test" on myns.projB, I get the ImportError. See error.txt, attached, for the transcript. I've also attached the two test packages as described. I notice now that the error appears to only occur when nose.collector is used... and when the package_dir of the child package is overridden. Perhaps this needs to go to the nose project and instead of the distutils project.
Please advise on what I might do next to help resolve this issue. Obviously I could restructure my projects to avoid the problem, but I would much rather help resolve the problem, as I suspect it may affect other users' deployments as well.
I can't reproduce this using the archive you uploaded. After running develop on projA, I ran test on projB and got an error message about nose not being available, so I added tests_require="nose" to projB, and then I got a run that said zero tests ran.
Phillip, You're right. I was running the tests on my two Windows Vista environments, and now I discover the problem only exhibits itself under Windows. I expanded the packages to my Ubuntu 8.04 box, and after installing nose (as you pointed out), the tests also ran (minimally) without incident. I then copied the packages to a brand-new Windows Vista install. I installed Python 2.5.2, setuptools-0.6c8, and nose 0.10.3. I then installed myns.projA using develop, and attempted to run "setup.py test" on myns.projB, and the error did exhibit itself. Additionally, I tested the sample on Windows XP (Python 2.5.2) and it also exhibits the error. Thanks to your help, I've further narrowed down the problem. I have filed a ticket with the nose tracker: http://code.google.com/p/python-nose/issues/detail?id=197 Any further suggestions are always appreciated. Regards, Jason -----Original Message----- From: Phillip J. Eby [mailto:pje@telecommunity.com] Sent: Sunday, 29 June, 2008 21:21 To: Jason R. Coombs; distutils-sig@python.org Subject: Re: [Distutils] ImportError running 'test' on namespace package - other package in namespace not found I can't reproduce this using the archive you uploaded. After running develop on projA, I ran test on projB and got an error message about nose not being available, so I added tests_require="nose" to projB, and then I got a run that said zero tests ran.
It seems that error messages are stripped... so I've uploaded the test case to here: http://www.filedropper.com/myns and below is the error message I mentioned was attached previously. Jason PS C:\Users\jaraco\projects\distutils_namespace\myns.projB> ./setup test running test running egg_info creating src\myns.projB.egg-info writing requirements to src\myns.projB.egg-info\requires.txt writing src\myns.projB.egg-info\PKG-INFO writing namespace_packages to src\myns.projB.egg-info\namespace_packages.txt writing top-level names to src\myns.projB.egg-info\top_level.txt writing dependency_links to src\myns.projB.egg-info\dependency_links.txt writing entry points to src\myns.projB.egg-info\entry_points.txt writing manifest file 'src\myns.projB.egg-info\SOURCES.txt' reading manifest file 'src\myns.projB.egg-info\SOURCES.txt' writing manifest file 'src\myns.projB.egg-info\SOURCES.txt' running build_ext Failure: ImportError (No module named projA.modA) ... ERROR ====================================================================== ERROR: Failure: ImportError (No module named projA.modA) ---------------------------------------------------------------------- Traceback (most recent call last): File "c:\program files (x86)\python\lib\site-packages\nose-0.10.3-py2.5.egg\nose\loader.py", line 364, in loadTestsFro mName addr.filename, addr.module) File "c:\program files (x86)\python\lib\site-packages\nose-0.10.3-py2.5.egg\nose\importer.py", line 39, in importFromP ath return self.importFromDir(dir_path, fqname) File "c:\program files (x86)\python\lib\site-packages\nose-0.10.3-py2.5.egg\nose\importer.py", line 84, in importFromD ir mod = load_module(part_fqname, fh, filename, desc) File "C:\Users\jaraco\projects\distutils_namespace\myns.projB\test\testBasic.py", line 1, in <module> from myns.projA.modA import funcA ImportError: No module named projA.modA ---------------------------------------------------------------------- Ran 1 test in 0.014s FAILED (errors=1)
participants (3)
-
Jason R. Coombs
-
oliviajohn123123@hotmail.com
-
Phillip J. Eby