gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 20:28:23 24 4
gpt4 key购买 nike

我正在为 Plone 4 开发一个产品,在安装的 zeocluster/src/... 目录中,我有一个自动化测试。不幸的是,当我运行“bin/client1 shell”然后运行 ​​(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')

最佳答案

最好是编辑您的 buildout.cfg 并添加一个创建“bin/test”脚本的部分。像这样:

[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/test -s your.package”仅运行 your.package 的测试,前提是 your.package 是实例中的 egg 的一部分。

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

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

关于python - 我如何在 Plone 4 开发的产品中运行测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5599844/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com