Access JSON response data easily
masterThe client provided by pytest-flask makes it easy to access JSON data in responses via the .json attribute.
Note: If your application uses a custom response class that already defines a .json attribute or method, pytest-flask will not overwrite it. You can implement custom deserialization by subclassing flask.Response and setting it as app.response_class in your fixture.
@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'}