Package: pytest-flask
pytest-flaskAn extension ofpytesttest 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
thePyPIoverview page orpackage documentation.How to start?Considering the minimal flaskapplication factorybelow inmyapp.pyas an example:fromflaskimportFlaskdefcreate_app():# create a minimal appapp=Flask(__name__)# simple hello world view@app.route('/hello')defhello():return'Hello, World!'returnappYou first need to define your application fixture inconftest.py:frommyappimportcreate_app@pytest.fixturedefapp():app=create_app()returnappFinally, install the extension with dependencies and run your test suite:$ pip install pytest-flask
$ pytestContributingDon’t hesitate to create aGitHub issuefor any bug or
suggestion. For more information check our contributionguidelines.Changelog1.3.0 (2023-10-23)Fix compatibility withFlask 3.0– the consequence is that the deprecated and incompatiblerequest_ctxhas been removed.1.2.1Fix bug in:meth:pytest_flask.fixtures.live_serverwhereSESSION_COOKIE_DOMAINwas set to false due tooriginal_server_namedefaulting to “localhost”.
The new default is “localhost.localdomain”.Drop support for python 3.6 and 3.51.2.0 (2021-02-26)Remove deprecated:meth:live_server.urlfixturerequest_ctx is now deprecatedand will be removed in the futureJSONReponse.jsonremoved in favour ofWerkzeug.wrappers.Response.json1.1.0 (2020-11-08)Speedup live server start time. Usesocketinstead of server
pulling (#58) to check server availability and add new--live-server-waitoption to set the live server wait timeout.
Thanks to@jadkik.1.0.0 (2020-03-03)Importantlive_serveris nowsession-scoped by default. This can be changed by using thelive-server_scopeoption in yourpytest.ini(#113). Thanks@havok2063for the initial patch and@TWood67for 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)FixImportErrorwithWerkzeug 1.0.0rc1(#105).0.15.0 (2019-05-13)Properly register theoptionsmarker (#97).0.14.0 (2018-10-15)New--live-server-hostcommand-line option to set the host name used by
thelive_serverfixture.Thanks@o1dafor the PR (#90).0.13.0 (2018-09-29)JSONReponsenow supports comparison directly with status codes:assertclient.get('invalid-route',headers=[('Accept','application/json')])==404Thanks@dusktreaderfor the PR (#86).0.12.0 (2018-09-06)pytest-flasknow requirespytest>=3.6(#84).Add new--live-server-portoption to select the port the live server will use (#82).
Thanks@RazerMfor the PR.Nowlive_serverwill try to stop the server cleanly by emitting aSIGINTsignal 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-stopin the command-line (#49).
Thanks@jadkikfor the PR.Internal fixes silence pytest warnings, more visible now withpytest-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@mattwbarryfor the PR.Fix broken link to pytest documentation (#50), thanks to@jineshpaloorfor the PR.Tox support (#48), thanks to@steenzoutfor the PR.AddLICENSEinto 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-serveroptions 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.appis nowpytest.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.1Minor changes in documentation.0.8.0Newrequest_ctxfixture which contains all request relevant
information (#29).0.7.5Use pytestmonkeypathfixture to teardown application config (#27).0.7.4Better test coverage, e.g. tests for available fixtures and markers.0.7.3Use retina-ready badges in documentation (#21).0.7.2Use pytestmonkeypatchfixture to rewrite live server name.0.7.1Single-sourcing package version (#24), as per“Python Packaging User Guide”.0.7.0Add package documentation (#20).0.6.3Better documentation in README with reST formatting (#18), thanks
to@greedo.0.6.2Release the random port before starting the application live server (#17),
thanks to@davehunt.0.6.1Bind 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-portoption.0.6.0Fix typo in option help for--liveserver-port, thanks to@svenstaro.0.5.0Addlive_serverfixture uses to run application in the background (#11),
thanks to@svenstaro.0.4.0Addclient_classfixture for class-based tests.0.3.4Include package requirements into distribution (#8).0.3.3Explicitly pin package dependencies and their versions.0.3.2Usecodecsmodule to open files to prevent possible errors on open
files which contains non-ascii characters.0.3.1First 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.