Skip to main content
Warning: You are using the test version of PyPI. This is a pre-production deployment of Warehouse. Changes made here affect the production instance of TestPyPI (
Help us improve Python packaging - Donate today!

A set of py.test fixtures to test Flask applications.

Project Description

A set of pytest fixtures to test Flask extensions and applications.


Plugin provides some fixtures to simplify app testing:

  • client - an instance of app.test_client,
  • client_class - client fixture for class-based tests,
  • config - the application config,
  • live_server - runs an application in the background (useful for tests with Selenium and other headless browsers),
  • request_ctx - the request context,
  • 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.options marker:

def test_app(app):
  assert not app.debug, 'Ensure the app not in debug mode'

During tests execution the request context has been pushed, 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:

def ping():
    return jsonify(ping='pong')

def test_api_ping(client):
    res = client.get(url_for(''))
    assert res.json == {'ping': 'pong'}

If you want your tests done via Selenium or other headless browser use the live_server fixture. The server’s URL can be retrieved using the url_for function:

from flask import url_for

class TestLiveServer:

    def test_server_is_up_and_running(self):
        res = urllib2.urlopen(url_for('index', _external=True))
        assert b'OK' in
        assert res.code == 200

Quick Start

To start using a plugin define your application fixture in

from myapp import create_app

def app():
    app = create_app()
    return app

Install the extension with dependencies and run your test suite:

$ pip install pytest-flask
$ py.test


The latest documentation is available at


Don’t hesitate to create a GitHub issue for any bug or suggestion.

Release History

Release History

This version
History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
pytest_flask-0.9.0-py2.py3-none-any.whl (8.6 kB) Copy SHA256 Checksum SHA256 2.7 Wheel Sep 15, 2015
pytest-flask-0.9.0.tar.gz (15.0 kB) Copy SHA256 Checksum SHA256 Source Sep 15, 2015

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting