Skip to main content

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

Project description

pytest-flask

PyPi version conda-forge version CI status PyPi downloads Documentation status Maintenance GitHub last commit GitHub closed pull requests GitHub closed issues PyPI - Downloads Code size License Issues style

An extension of pytest test runner which provides a set of useful tools to simplify testing and development of the Flask extensions and applications.

To view a more detailed list of extension features and examples go to the PyPI overview page or package documentation.

How to start?

Considering the minimal flask application factory below in myapp.py as an example:

from flask import Flask

def create_app():
   # create a minimal app
   app = Flask(__name__)

   # simple hello world view
   @app.route('/hello')
   def hello():
      return 'Hello, World!'

   return app

You first need to define your application fixture in conftest.py:

from myapp import create_app

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

Finally, install the extension with dependencies and run your test suite:

$ pip install pytest-flask
$ pytest

Contributing

Don’t hesitate to create a GitHub issue for any bug or suggestion. For more information check our contribution guidelines.

Changelog

1.3.0 (2023-10-23)

  • Fix compatibility with Flask 3.0 – the consequence is that the deprecated and incompatible request_ctx has been removed.

1.2.1

  • Fix bug in :meth:pytest_flask.fixtures.live_server where SESSION_COOKIE_DOMAIN was set to false due to original_server_name defaulting to “localhost”. The new default is “localhost.localdomain”.

  • Drop support for python 3.6 and 3.5

1.2.0 (2021-02-26)

  • Remove deprecated :meth:live_server.url

  • fixture request_ctx is now deprecated and will be removed in the future

  • JSONReponse.json removed in favour of Werkzeug.wrappers.Response.json

1.1.0 (2020-11-08)

  • Speedup live server start time. Use socket instead of server pulling (#58) to check server availability and add new --live-server-wait option to set the live server wait timeout. Thanks to @jadkik.

1.0.0 (2020-03-03)

Important

  • live_server is now session-scoped by default. This can be changed by using the live-server_scope option in your pytest.ini (#113). Thanks @havok2063 for the initial patch and @TWood67 for finishing it up.

  • pytest 5.2 or later is now required.

  • Python 2.7 and 3.4 are no longer supported.

0.15.1 (2020-02-03)

  • Fix ImportError with Werkzeug 1.0.0rc1 (#105).

0.15.0 (2019-05-13)

  • Properly register the options marker (#97).

0.14.0 (2018-10-15)

  • New --live-server-host command-line option to set the host name used by the live_server fixture.

    Thanks @o1da for the PR (#90).

0.13.0 (2018-09-29)

  • JSONReponse now supports comparison directly with status codes:

    assert client.get('invalid-route', headers=[('Accept', 'application/json')]) == 404

    Thanks @dusktreader for the PR (#86).

0.12.0 (2018-09-06)

  • pytest-flask now requires pytest>=3.6 (#84).

  • Add new --live-server-port option to select the port the live server will use (#82). Thanks @RazerM for the PR.

  • Now live_server will try to stop the server cleanly by emitting a SIGINT signal and waiting 5 seconds for the server to shutdown. If the server is still running after 5 seconds, it will be forcefully terminated. This behavior can be changed by passing --no-live-server-clean-stop in the command-line (#49). Thanks @jadkik for the PR.

  • Internal fixes silence pytest warnings, more visible now with pytest-3.8.0 (#84).

0.11.0 (compared to 0.10.0)

  • Implement deployment using Travis, following in line with many other pytest plugins.

  • Allow live server to handle concurrent requests (#56), thanks to @mattwbarry for the PR.

  • Fix broken link to pytest documentation (#50), thanks to @jineshpaloor for the PR.

  • Tox support (#48), thanks to @steenzout for the PR.

  • Add LICENSE into distribution (#43), thanks to @danstender.

  • Minor typography improvements in documentation.

  • Add changelog to documentation.

0.10.0 (compared to 0.9.0)

  • Add --start-live-server/--no-start-live-server options to prevent live server from starting automatically (#36), thanks to @EliRibble.

  • Fix title formatting in documentation.

0.9.0 (compared to 0.8.1)

  • Rename marker used to pass options to application, e.g. pytest.mark.app is now pytest.mark.options (#35).

  • Documentation badge points to the package documentation.

  • Add Travis CI configuration to ensure the tests are passed in supported environments (#32).

0.8.1

  • Minor changes in documentation.

0.8.0

  • New request_ctx fixture which contains all request relevant information (#29).

0.7.5

  • Use pytest monkeypath fixture to teardown application config (#27).

0.7.4

  • Better test coverage, e.g. tests for available fixtures and markers.

0.7.3

  • Use retina-ready badges in documentation (#21).

0.7.2

  • Use pytest monkeypatch fixture to rewrite live server name.

0.7.1

0.7.0

  • Add package documentation (#20).

0.6.3

  • Better documentation in README with reST formatting (#18), thanks to @greedo.

0.6.2

  • Release the random port before starting the application live server (#17), thanks to @davehunt.

0.6.1

  • Bind live server to a random port instead of 5000 or whatever is passed on the command line, so it’s possible to execute tests in parallel via pytest-dev/pytest-xdist (#15). Thanks to @davehunt.

  • Remove --liveserver-port option.

0.6.0

  • Fix typo in option help for --liveserver-port, thanks to @svenstaro.

0.5.0

  • Add live_server fixture uses to run application in the background (#11), thanks to @svenstaro.

0.4.0

  • Add client_class fixture for class-based tests.

0.3.4

  • Include package requirements into distribution (#8).

0.3.3

  • Explicitly pin package dependencies and their versions.

0.3.2

  • Use codecs module to open files to prevent possible errors on open files which contains non-ascii characters.

0.3.1

First release on PyPI.

The MIT License (MIT)

Copyright © 2014–2016 Vital Kudzelka and contributors.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Project details


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-1.3.0.tar.gz (35.8 kB view details)

Uploaded Source

Built Distribution

pytest_flask-1.3.0-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pytest-flask-1.3.0.tar.gz
  • Upload date:
  • Size: 35.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.1 CPython/3.11.6

File hashes

Hashes for pytest-flask-1.3.0.tar.gz
Algorithm Hash digest
SHA256 58be1c97b21ba3c4d47e0a7691eb41007748506c36bf51004f78df10691fa95e
MD5 c1513c6304aca8b04986cafc3ee39953
BLAKE2b-256 fb2332b36d2f769805c0f3069ca8d9eeee77b27fcf86d41d40c6061ddce51c7d

See more details on using hashes here.

File details

Details for the file pytest_flask-1.3.0-py3-none-any.whl.

File metadata

  • Download URL: pytest_flask-1.3.0-py3-none-any.whl
  • Upload date:
  • Size: 13.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.1 CPython/3.11.6

File hashes

Hashes for pytest_flask-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c0e36e6b0fddc3b91c4362661db83fa694d1feb91fa505475be6732b5bc8c253
MD5 5d7f84757ff162e59e24cf6310fdde34
BLAKE2b-256 de037a917fda3d0e96b4e80ab1f83a6628ec4ee4a882523b49417d3891bacc9e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page