1

我已经为 Plone 4.2 开发了一个附加组件,并且正在编写测试。当我执行

# bin/test -s my.stream

我收到以下错误: 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'

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}

我的测试.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')

我错过了什么?

提前致谢。

4

1 回答 1

7

您需要进行单元测试以加载依赖包 ZCML。它们不会自动加载(与 Plone 启动时不同),因为加载所有不需要的包会大大减慢运行测试的速度。

有几种方法可以解决这个问题,但这很可能会奏效:

def setUpZope(self, app, configurationContext):
    # Load ZCML
    import my.common
    self.loadZCML(package=my.common)

    # my.setup goes here

此外,包应该分层,以便如果my.common提供测试,那么您的my.stream测试层将依赖于my.common层并记住调用它们的super()方法,以便类层次结构负责初始化依赖包。

于 2013-09-06T06:42:55.733 回答