K
K
KIN19912016-05-30 14:13:51
Flask
KIN1991, 2016-05-30 14:13:51

How to do unit tests in Flask?

Hello everyone, I have an application in Flask. How can tests be organized for it, in which a test database would be created, which would be a copy of the production database (like in Django)?
Does this require Flask migrations?
PS In Flask I use alchemy as a form

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2016-05-30
@KIN1991

1. Download Miguel's book. This is the Flask bible. Without her, as without hands!
2. I use flask-sqlalchemy , and create a base for tests using sqllite in memory
3. To access a client that can send requests to your web server, you can use client something like this:

class ApplicationTestCase(unittest.TestCase):

    def setUp(self):
        self.app = create_app(config_name='testing')
        self.app_ctx = self.app.app_context()
        self.app_ctx.push()
        db.create_all()
        self.client = self.app.test_client()

R
Roman, 2016-05-30
@skipirich

Look, maybe this will help blog.miguelgrinberg.com/post/the-flask-mega-tutori... there is a Unit testing framework section about in the middle of the page

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question