迁移到plone.app.testing后测试模块导入失败 - 显然是循环导入

时间:2014-02-17 09:10:44

标签: python testing plone

我正面临将Plone网站迁移到使用plone.app.testing的问题。我收到消息Test-module import failures作为控制台输出的第一行。

C:\sandbox\cms.buildout>bin\test -s soschildrensvillages
Test-module import failures:

Module: soschildrensvillages.contenttypes.tests.test_portlet_concept_news

Traceback (most recent call last):
...
  File "c:\sandbox\cms.buildout\src\soschildrensvillages\soschildrensvillages\contenttypes\content\concept_folder.py", line 7, in <module>
    from plone.app.folder.folder import ATFolder
  File "c:\sandbox\cms.buildout\eggs\plone.app.folder-1.0.5-py2.7.egg\plone\app\folder\folder.py", line 4, in <module>
    from Products.ATContentTypes.interface import IATFolder
  File "c:\sandbox\cms.buildout\eggs\products.atcontenttypes-2.1.13-py2.7.egg\Products\ATContentTypes\__init__.py", line 32, in <module>
    import Products.ATContentTypes.content
  File "c:\sandbox\cms.buildout\eggs\products.atcontenttypes-2.1.13-py2.7.egg\Products\ATContentTypes\content\__init__.py", line 7, in <module>
    import Products.ATContentTypes.content.folder
  File "c:\sandbox\cms.buildout\eggs\products.atcontenttypes-2.1.13-py2.7.egg\Products\ATContentTypes\content\folder.py", line 19, in <module>
    from plone.app.folder import folder
ImportError: cannot import name folder

尝试设置测试图层并运行测试时,会有更多导入错误。只有单元测试(普通TestCase)才能正常运行。

这些错误仅在我从Products.PloneTestCase迁移最后一个测试后才开始出现,并且在我们的testing.py模块中包含以下行解决了这个问题。

from Products.PloneTestCase import PloneTestCase as ptc

我不确定某人需要提供什么样的详细信息才能提供帮助,但是对我能尝试的内容的任何指示都将非常感激。

我们的testing.py看起来像

products = ('collective.lineage', 'soschildrensvillages')


class SOSChildrenLayer(PloneWithPackageLayer):

    defaultBases = (PLONE_FIXTURE,)

    def __init__(self):
        super(SOSChildrenLayer, self).__init__(
                zcml_filename='configure.zcml', zcml_package=soschildrensvillages,
                additional_z2_products=products, gs_profile_id='soschildrensvillages:default'
        )

    def setUpZCMLFiles(self):
        super(SOSChildrenLayer, self).setUpZCMLFiles()
        self.loadZCML(name='overrides.zcml', package=soschildrensvillages)

    def tearDownZope(self, app):
        super(SOSChildrenLayer, self).tearDownZope(app)
        for product in products:
            z2.uninstallProduct(app, product)


SOS_CHILDREN_FIXTURE = SOSChildrenLayer()
SOS_CHILDREN_INTEGRATION_TESTING = IntegrationTesting(
        bases=(SOS_CHILDREN_FIXTURE,), 
        name="SOSChildren:Integration"
    )

在setup.py中我们有

  install_requires=[
      'setuptools',

      'collective.lineage',

      'plone.app.caching',
      'plone.app.folder',
      'plone.app.iterate',

      'quintagroup.seoptimizer',

      'rdflib',

      'soschildrensvillages.taxonomy',          
      'soschildren.contentexperiments',          

      'Products.AdvancedQuery',
      'Products.ATContentTypes',
      'Products.CMFPlone',
      'Products.CMFPlacefulWorkflow'
      # -*- Extra requirements: -*-
  ],

在configure.zcml中我们有

  <includeDependencies package="." />

concept_folder.py包含Archetypes内容类型的定义。

1 个答案:

答案 0 :(得分:0)

我通过确保在我的模块中的plone.app.folder之前从Products.ATContentTypes导入了一些东西来解决这个错误。

from plone.app.folder.folder import ATFolder
from plone.app.folder.folder import ATFolderSchema
from Products.ATContentTypes.content.schemata import finalizeATCTSchema

from Products.ATContentTypes.content.schemata import finalizeATCTSchema
from plone.app.folder.folder import ATFolder
from plone.app.folder.folder import ATFolderSchema