JiL
JiL

Reputation: 65

Import Error: No module named testrunner

I followed this to add zc.recipe.testrunner to my buildout. I can run buildout successfully but when I run bin/test, I get:

ImportError: No module named testrunner

I have zope.testrunner-4.0.4-py2.4.egg in

/usr/local/lib/python2.4/site-packages

I also pinned

zope.testrunner = 4.0.4
zc.recipe.testruner = 1.4.0
zc.recipe.egg = 1.3.2

When I ran buildout, I used -vvv and I got:

...
Installing 'zc.recipe.testrunner'.
We have the distribution that satisfies 'zc.recipe.testrunner==1.4.0'.
Egg from site-packages: z3c.recipe.scripts 1.0.1
Egg from site-packages: zope.testrunner 4.0.4
Egg from site-packages: zope.interface 3.8.0
Egg from site-packages: zope.exceptions 3.7.1
...
We have the distribution that satisfies 'zope.testrunner==4.0.4'.
Egg from site-packages: zope.testrunner 4.0.4
Adding required 'zope.interface'
 required by zope.testrunner 4.0.4.
We have a develop egg: zope.interface 0.0
Adding required 'zope.exceptions'
 required by zope.testrunner 4.0.4.
We have a develop egg: zope.exceptions 0.0
...

Why is it I get an ImportError? Is zope.testrunner not installed correctly?

Edit:

This is the relevant part in my buildout:

[buildout]
...
parts =
    ...
    test

[test]
recipe = zc.recipe.testrunner
defaults = ['--auto-color', '--auto-progress']
eggs = 
    my.product

This is the content in bin/test:

#!/usr/local/bin/python2.4 -S

import sys
sys.path[0:0] = [
    '/home/jil/mySandbox/myTrunk/parts/test/site-packages',
    ]


import os
path = sys.path[0]
if os.environ.get('PYTHONPATH'):
    path = os.pathsep.join([path, os.environ['PYTHONPATH']])
os.environ['BUILDOUT_ORIGINAL_PYTHONPATH'] = os.environ.get('PYTHONPATH', '')
os.environ['PYTHONPATH'] = path
import site # imports custom buildout-generated site.py
import os
sys.argv[0] = os.path.abspath(sys.argv[0])
os.chdir('/home/jil/mySandbox/myTrunk/parts/test/working-directory')

import zope.testrunner

if __name__ == '__main__':
    zope.testrunner.run((['--auto-color', '--auto-progress']) + [
        '--test-path', '/home/jil/mySandbox/myTrunk/src/my.product',
        ])    

This is the error after running bin/test:

Traceback (most recent call last):
File "/home/jil/mySandbox/myTrunk/bin/test", line 20, in ?
  import zope.testrunner
ImportError: No module named testrunner

Upvotes: 2

Views: 2612

Answers (1)

logc
logc

Reputation: 3923

I had the same problem. At least in my case, the cause was mixing dependencies already installed in 'site-packages' and dependencies installed by buildout in 'eggs': zope.deprecation and zope.interface were already in my 'site-packages' directory and thus were not re-installed by buildout. The path manipulation on the 'bin/test' executable seemed to import the 'zope' package from 'site-packages', without the 'testrunner' subpackage.

Try removing all zope.* packages from 'site-packages' and re-run buildout, or use 'include-site-packages = false' in the '[buildout]' section of your buildout.cfg. The first solution worked for me.

Upvotes: 1

Related Questions