Skip to main content

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,

  • client_class - client fixture for class-based tests,

  • 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.

Download files

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

Source Distribution

pytest-flask-0.4.0.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_flask-0.4.0-py2.py3-none-any.whl (6.5 kB view details)

Uploaded Python 2Python 3

File details

Details for the file pytest-flask-0.4.0.tar.gz.

File metadata

  • Download URL: pytest-flask-0.4.0.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pytest-flask-0.4.0.tar.gz
Algorithm Hash digest
SHA256 72dce0e4ad99b8d8a062833b8a963f81bb17a1f814acac7e59310644858dc064
MD5 dade570bffef849f8fd27a4aacfff81b
BLAKE2b-256 8e9c87d7b6ec33ca0cb3b604324e89a53094e06f50a35259f0bba189e7cd87f9

See more details on using hashes here.

File details

Details for the file pytest_flask-0.4.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_flask-0.4.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 450ffe48694a0cfb83f6f9a03c89800f16e7aaf13dbd3784045626b672dcf65b
MD5 d8c2211b58cf53907ed7db965dd0f1a2
BLAKE2b-256 297702c8f9097213607efcd53d98b8b1189c391745bfdf31821acbe302650168

See more details on using hashes here.

Release history Release notifications | RSS feed

1.3.0

2 files

1.2.0

2 files

1.1.0

2 files

1.0.0

2 files

0.15.1

2 files

0.15.0

2 files

0.14.0

2 files

0.13.0

2 files

0.12.0

2 files

0.11.0

2 files

0.10.0

2 files

0.9.0

2 files

0.8.1

2 files

0.8.0

2 files

0.7.5

2 files

0.7.4

2 files

0.7.3

2 files

0.7.2

2 files

0.7.1

2 files

0.7.0

2 files

0.6.3

2 files

0.6.2

2 files

0.6.1

2 files

0.6.0

2 files

0.5.0

2 files

This release

0.4.0 This release

2 files

0.3.4

2 files

0.3.3

2 files

0.3.2

2 files

0.3.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page