我正在为Plone 4开发一个产品,在安装的zeocluster/src/...目录中,我有一个自动化测试。不幸的是,当我运行‘bin/client1shell’然后运行(path to Plone's Python)/bin/python setup.py test时,它失败了。错误是
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中,
...
test_suite = "nose.collector"
...失败的测试:
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')发布于 2011-04-09 06:31:34
最好的方法是编辑你的测试,并添加一个创建‘bin/ buildout.cfg’脚本的部分。如下所示:
[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;您可以看看它来获得灵感。
发布于 2011-04-09 22:25:29
您需要使用zope.testrunner和zope.testing来运行测试。Plone测试不能通过nose运行,我们也不支持setuptools发明的setup.py的'test_suite‘参数。
其他答案解释了如何设置测试运行器脚本。
发布于 2011-04-09 06:22:00
ptc.setupPloneSite()注册一个延迟函数,该函数将在设置zope.testrunner层时实际运行。我猜您没有使用zope.testrunner,因此没有设置层,因此Plone站点永远不会被创建,因此在随后尝试获取门户对象时会使用AttributeError。
https://stackoverflow.com/questions/5599844
复制相似问题