Testing Flask
Throughout this book we’ll have various examples. To make sure they work properly we’ll also have tests for these examples. This is the test for the example with Flask. It uses pytest and it has another example of a decorator. Here we decorate a function to become a fixture.
import pytest
import flask_app
@pytest.fixture()
def web():
return flask_app.app.test_client()
def test_main_page(web):
rv = web.get('/')
assert rv.status == '200 OK'
assert b'Hello World!' == rv.data
def test_main_page(web):
rv = web.get('/login')
assert rv.status == '200 OK'
assert b'Showing the login page ...' == rv.data