Skip to content

Latest commit

 

History

History
62 lines (47 loc) · 3.03 KB

flask-testing.md

File metadata and controls

62 lines (47 loc) · 3.03 KB
title
Flask / Testing

Flask / Testing

Hello, World!

myapp/hello/__init__.py:

from flask import Blueprint

blueprint = Blueprint('hello', __name__, url_prefix='/hello')

@blueprint.route('/<somebody>')
def hello(somebody='World'):
    return 'Hello, %s!' % somebody

tests/conftest.py:

from myapp import create_app
import pytest

@pytest.fixture
def client():
    app = create_app()
    return app.test_client()

tests/test_hello.py:

def test_hello__somebody__hello_somebody(client):
    resp = client.get('/hello/Flask')
    assert resp.data == 'Hello, Flask!'

內建對 Testing 的支援??

參考資料

手冊: