【发布时间】:2016-03-29 17:42:39
【问题描述】:
我正在尝试调用以下方法,post_sample(文件名 index.py):
class Main(Resource):
@app.route('/sample', methods=['POST'])
def post_sample():
return 'POST received'
来自以下单元测试代码:
def test_post():
Main().post_sample()
print 'test_here'
但是当我运行时出现以下错误,我无法理解:
> Main().post_sample()
E TypeError: post_sample() takes no arguments (1 given)
tests/test_post.py:8: TypeError
TIA!
【问题讨论】:
-
为什么你的视图函数周围有一个类?
-
您是否使用test client 进行单元测试?
-
@wgwz 因为我有一些函数,所以我将它们封装在一个类中。
-
@idjaw 不,我正在使用 py.test
-
@mr-sk 查看 Flask 的测试客户端,它做得非常好,将有助于您的单元测试。
标签: python unit-testing flask python-unittest