我有一些 API 端点需要测试,但我不确定从哪里开始。我正在使用 Bottle 框架,我正在测试的方法之一是从请求中读取参数。我如何在测试环境中对此进行模拟?
最佳答案
使用boddle如果您想访问正常的 bottle 语法,则用于单元测试。示例:
import bottle, unittest
from boddle import boddle
@bottle.get('/woot')
def woot():
return bottle.request.params['name']
class TestIt(unittest.TestCase):
def testWoot(self):
with boddle(params={'name':'derek'}):
self.assertEqual(woot(), 'derek')
if __name__=='__main__':
unittest.main()
关于python - 如何使用 Bottle 框架进行单元测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27305449/