我为Plone 4.2开发了一个附加组件,我正在编写测试.当我执行
# bin/test -s my.stream
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:KeyError:u'profile-my.common:default' 为什么我收到错误?
这里有一些可能有用的信息.
追溯:
Traceback (most recent call last):
File "/blah/user/blah/00-buildout/eggs/zope.testing-3.9.7-py2.6.egg/zope/testing /testrunner/runner.py", line 366, in run_layer
setup_layer(options, layer, setup_layers)
File "/blah/user/blah/00-buildout/eggs/zope.testing-3.9.7-py2.6.egg/zope/testing/testrunner/runner.py", line 628, in setup_layer
setup_layer(options, base, setup_layers)
File "/blah/user/blah/00-buildout/eggs/zope.testing-3.9.7-py2.6.egg/zope/testing/testrunner/runner.py", line 633, in setup_layer
layer.setUp()
File "/blah/user/blah/00-buildout/eggs/plone.app.testing-4.2-py2.6.egg/plone/app/testing/helpers.py", line 343, in setUp
self.setUpPloneSite(portal)
File "/blah/user/blah/venv26/buildout/src/my.stream/my/stream/testing.py", line 20, in setUpPloneSite
applyProfile(portal, 'my.stream:default')
File "/blah/user/blah/00-buildout/eggs/plone.app.testing-4.2-py2.6.egg/plone/app/testing/helpers.py", line 113, in applyProfile
setupTool.runAllImportStepsFromProfile(profileId)
File "/blah/user/blah/00-buildout/eggs/Products.GenericSetup-1.7.1-py2.6.egg/Products/GenericSetup/tool.py", line 353, in runAllImportStepsFromProfile
ignore_dependencies=ignore_dependencies)
- __traceback_info__: profile-my.stream:default
File "/blah/user/blah/00-buildout/eggs/Products.GenericSetup-1.7.1-py2.6.egg/Products/GenericSetup/tool.py", line 1095, in _runImportStepsFromContext
chain = self.getProfileDependencyChain( profile_id )
File "/blah/user/blah/00-buildout/eggs/Products.GenericSetup-1.7.1-py2.6.egg/Products/GenericSetup/tool.py", line 1078, in getProfileDependencyChain
chain.extend(self.getProfileDependencyChain( dependency, seen ))
File "/blah/user/blah/00-buildout/eggs/Products.GenericSetup-1.7.1-py2.6.egg/Products/GenericSetup/tool.py", line 1078, in getProfileDependencyChain
chain.extend(self.getProfileDependencyChain( dependency, seen ))
File "/blah/user/blah/00-buildout/eggs/Products.GenericSetup-1.7.1-py2.6.egg/Products/GenericSetup/tool.py", line 1076, in getProfileDependencyChain
dependencies = self.getDependenciesForProfile( profile_id )
File "/blah/user/blah/00-buildout/eggs/Products.GenericSetup-1.7.1-py2.6.egg/Products/GenericSetup/tool.py", line 858, in getDependenciesForProfile
raise KeyError, profile_id
KeyError: u'profile-my.common:default'
Run Code Online (Sandbox Code Playgroud)
my.stream依赖于my.common.两者都是/ blah/user/blah/buildout/src中的附加组件.它们由mr.developer管理.
我的扩建包括所有开发蛋:
[buildout]
...
eggs =
my.common
my.stream
...
[test]
recipe = zc.recipe.testrunner
defaults = ['--auto-color', '--auto-progress']
eggs =
${instance:eggs}
Run Code Online (Sandbox Code Playgroud)
我的testing.py:
from plone.app.testing import PloneSandboxLayer
from plone.app.testing import applyProfile
from plone.app.testing import PLONE_FIXTURE
from plone.app.testing import IntegrationTesting
from zope.configuration import xmlconfig
class MyStreamContent(PloneSandboxLayer):
defaultBases = (PLONE_FIXTURE,)
def setUpZope(self, app, configurationContext):
# Load ZCML
import my.stream
xmlconfig.file('configure.zcml',
my.stream,
context=configurationContext)
def setUpPloneSite(self, portal):
applyProfile(portal, 'my.stream:default')
MY__FIXTURE = MyStreamContent()
MY__INTEGRATION_TESTING = IntegrationTesting(
bases=(MY__FIXTURE,),
name='MyStreamContent:Integration')
Run Code Online (Sandbox Code Playgroud)
我错过了什么?
提前致谢.
您需要进行单元测试以加载依赖包ZCML.它们不会自动加载(与Plone启动时不同),因为加载所有不需要的软件包会大大减慢运行测试的速度.
有几种方法,但这很可能有效:
def setUpZope(self, app, configurationContext):
# Load ZCML
import my.common
self.loadZCML(package=my.common)
# my.setup goes here
Run Code Online (Sandbox Code Playgroud)
此外,包应该是分层的,这样如果my.common提供测试,那么my.stream测试层将依赖于my.common层并记住调用它们的super()方法,因此类层次结构将负责初始化依赖包.
| 归档时间: |
|
| 查看次数: |
246 次 |
| 最近记录: |