A set of py.test fixtures to test Flask applications.
Project description
A set of py.test fixtures to test Flask extensions and applications.
Features
Plugin provides some fixtures to simplify app testing:
client - an instance of app.test_client,
config - you application config,
accept_json, accept_jsonp, accept_any - accept headers suitable to use as parameters in client.
To pass options to your application use the pytest.mark.app marker:
@pytest.mark.app(debug=False)
def test_app(app):
assert not app.debug, 'Ensure the app not in debug mode'
During tests execution the application has pushed context, e.g. url_for, session and other context bound objects are available without context managers:
def test_app(client):
assert client.get(url_for('myview')).status_code == 200
Response object has a json property to test a view that returns a JSON response:
@api.route('/ping')
def ping():
return jsonify(ping='pong')
def test_api_ping(client):
res = client.get(url_for('api.ping'))
assert res.json == {'ping': 'pong'}
Quick Start
To start using a plugin define you application fixture in conftest.py:
from myapp import create_app
@pytest.fixture
def app():
app = create_app()
return app
And run your test suite:
$ pip install pytest-flask
$ py.test
Contributing
Don’t hesitate to create a GitHub issue for any bug or suggestion.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pytest_flask-0.3.4-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f099043f22b9acb291243e0d89e1f086cfb3144e4d8e7ce2015c9f8f4ea4d08 |
|
MD5 | c1af483fc5649c32fc50ed9786eb2c2c |
|
BLAKE2b-256 | 4efd2d657292ee9f7f3ac3a0b76c2234dd4ac0c443533a044cab91c750be8697 |