【问题标题】:Test-module import failures after migrating to plone.app.testing - apparently circular imports迁移到 plone.app.testing 后测试模块导入失败 - 显然是循环导入
【发布时间】:2014-02-20 00:00:39
【问题描述】:

我在将我们的 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

在尝试设置测试层和运行测试时出现更多导入错误。只有单元测试(plain 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 内容类型的定义。

【问题讨论】:

    标签: python testing plone


    【解决方案1】:

    我通过确保在我的模块中的 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
    

    【讨论】:

      猜你喜欢
      • 2019-01-11
      • 1970-01-01
      • 1970-01-01
      • 2019-04-28
      • 1970-01-01
      • 1970-01-01
      • 2012-09-02
      • 1970-01-01
      相关资源
      最近更新 更多