在尝试了#python 和#pocoo 之后来到这里。我正在为烧瓶应用程序编写单元测试,并想测试重定向。官方的烧瓶教程对此没有任何内容,所以我尝试使用它:http ://packages.python.org/Flask-Testing/
这是我到目前为止测试教程应用程序的代码(应用程序代码在这里:https ://github.com/mitsuhiko/flask/tree/master/examples/flaskr/ )
from flaskext.testing import TestCase
import flaskr
from flask import Flask
class FlaskrTest(TestCase):
def create_app(self):
app = Flask(__name__)
app.config['TESTING'] = True
return app
def test_add_entry(self, title, text):
resp = app.post('/add', data=dict(title='blah',
text='Blooh'), follow_redirects=True)
self.assertRedirects(resp, '/')
if __name__ == '__main__':
myTest = FlaskrTest()
myTest.test_add_entry()
这是我得到的错误:
Traceback (most recent call last):
File "flaskr_test.py", line 17, in <module>
myTest = FlaskrTest()
File "/usr/lib/python2.7/unittest/case.py", line 185, in __init__
(self.__class__, methodName))
ValueError: no such test method in <class '__main__.FlaskrTest'>: runTest
我会很感激任何帮助。:)