首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Plone 4中开发的产品中运行测试?

如何在Plone 4中开发的产品中运行测试?
EN

Stack Overflow用户
提问于 2011-04-09 03:22:25
回答 3查看 328关注 0票数 2

我正在为Plone 4开发一个产品,在安装的zeocluster/src/...目录中,我有一个自动化测试。不幸的是,当我运行‘bin/client1shell’然后运行(path to Plone's Python)/bin/python setup.py test时,它失败了。错误是

代码语言:javascript
复制
File "buildout-cache/eggs/Products.PloneTestCase-0.9.12-py2.6.egg/Products/PloneTestCase/PloneTestCase.py", line 109, in getPortal
    return getattr(self.app, portal_name)
AttributeError: plone

在Plone 4中运行自动化测试的正确方式是什么?

setup.py中,

代码语言:javascript
复制
...
test_suite = "nose.collector"
...

失败的测试:

代码语言:javascript
复制
import unittest

from Products.PloneTestCase import PloneTestCase as ptc

ptc.setupPloneSite()

class NullTest(ptc.PloneTestCase):        
    def testTest(self):
        pass

def test_suite():
    return unittest.TestSuite([
            unittest.makeSuite(NullTest)
        ])

if __name__ == '__main__':
    unittest.main(defaultTest='test_suite')
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2011-04-09 06:31:34

最好的方法是编辑你的测试,并添加一个创建‘bin/ buildout.cfg’脚本的部分。如下所示:

代码语言:javascript
复制
[test]
recipe = zc.recipe.testrunner
# Note that only tests for packages that are explicitly named (instead
# of 'implicitly' added to the instance as dependency) can be found.
eggs =
# Use the name of the plone.recipe.zope2instance part here, might be zeoclient instead: 
    ${instance:eggs}
defaults = ['--exit-with-status', '--auto-color', '--auto-progress']

别忘了在buildout.cfg的主'buildout‘部分的'parts’中添加'test‘。运行bin/buildout,您现在应该有了bin/test脚本。有关更多选项和解释,请参阅本食谱的PyPI page

现在,运行'bin/test‘应该会对实例部分中显式命名的所有鸡蛋运行所有测试。这可能会运行太多的测试。使用‘bin/ your.package -s your.package’仅运行your.package的测试,前提是your.package是实例中鸡蛋的一部分。

请注意,与其在测试中使用“通过”,不如添加一个肯定会失败的测试,比如“self.assertEqual(True,False)”。这样就更容易看到您的测试确实已经运行,并且如预期的那样失败。

当我有一个简单的构建来测试我正在开发的一个特定的包时,我通常会在最简单的构建中扩展一个配置,比如this one for Plone 4;您可以看看它来获得灵感。

票数 3
EN

Stack Overflow用户

发布于 2011-04-09 22:25:29

您需要使用zope.testrunner和zope.testing来运行测试。Plone测试不能通过nose运行,我们也不支持setuptools发明的setup.py的'test_suite‘参数。

其他答案解释了如何设置测试运行器脚本。

票数 3
EN

Stack Overflow用户

发布于 2011-04-09 06:22:00

ptc.setupPloneSite()注册一个延迟函数,该函数将在设置zope.testrunner层时实际运行。我猜您没有使用zope.testrunner,因此没有设置层,因此Plone站点永远不会被创建,因此在随后尝试获取门户对象时会使用AttributeError。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5599844

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档