The flask verification module does not have such a test method error

Comes here after trying #python and #pocoo. I am writing unit test for a flash application and want to check redirection. The official jar tutorials don't have this, so I tried using this: http://packages.python.org/Flask-Testing/

Here is the code that I have tested the training application so far (application code here: 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() 

and here is the error I get:

 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 

I would be grateful for any help. :)

+4
source share
1 answer

The easiest way to run tests is to use unittest.main to collect tests, because flask.ext.testing.TestCase is a subclass of unittest.TestCase . All other test collectors, such as nose with unittest.TestCase class unittest.TestCase , should work.

A simple example with unittest.main as follows:

 import unittest # Here your TestCases if __name__ == '__main__': unittest.main() 

unittest detect all of your test cases and test methods, but note that class and method names must begin with test .

Disclaimer: I am the custodian of Flocks-Testing.

+2
source

All Articles