我正在使用 python unittest 对路由函数进行单元测试。
@app.route('/some_func', methods=['POST'])
def some_func():
if request.method == 'POST':
return render_template('some_func_template.html')
我做了什么:
def test_some_func(self):
with app.test_client() as c:
response = c.post('/some_func')
self.assertEqual(response.status_code, 302)
当我运行coverage run filename.py 时,测试用例不会抛出错误。 但是在coverage html filename.py中,函数也没有被覆盖。
我也尝试过使用@patch。
我认为 request.method if 条件是这里的原因。
如何让单元测试覆盖此功能?
欢迎任何指点。