gpt4 book ai didi

unit-testing - Web2py 中的单元测试

转载 作者:行者123 更新时间:2023-12-04 14:43:11 25 4
gpt4 key购买 nike

我正在按照 this post 中的说明进行操作但无法让我的方法得到全局认可。

错误信息:

ERROR: test_suggest_performer (__builtin__.TestSearch)
----------------------------------------------------------------------
Traceback (most recent call last):
File "applications/myapp/tests/test_search.py", line 24, in test_suggest_performer
suggs = suggest_flavors("straw")
NameError: global name 'suggest_flavors' is not defined

我的测试文件:

import unittest

from gluon.globals import Request
db = test_db

execfile("applications/myapp/controllers/search.py", globals())

class TestSearch(unittest.TestCase):
def setUp(self):
request = Request()

def test_suggest_flavors(self):
suggs = suggest_flavors("straw")
self.assertEqual(len(suggs), 1)
self.assertEqual(suggs[0][1], 'Strawberry')

我的 Controller :

def suggest_flavors(term):
return []

有没有人在 web2py 中成功完成这样的单元测试?

最佳答案

请参阅:http://web2py.com/AlterEgo/default/show/260

请注意,在您的示例中,函数“suggest_flavors”应定义在“applications/myapp/controllers/search.py​​”中。

关于unit-testing - Web2py 中的单元测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2762294/

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