{"id":3773,"library":"pytest-flask","title":"pytest-flask","description":"pytest-flask is an extension for the pytest test runner, providing a set of useful fixtures and tools to simplify the testing and development of Flask applications and extensions. It is currently at version 1.3.0 and actively maintained, with releases typically tied to Flask and pytest major version updates and bug fixes.","status":"active","version":"1.3.0","language":"en","source_language":"en","source_url":"https://github.com/pytest-dev/pytest-flask","tags":["pytest","flask","testing","plugin","fixtures"],"install":[{"cmd":"pip install pytest-flask","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core testing framework that pytest-flask extends.","package":"pytest"},{"reason":"The web framework being tested.","package":"Flask"}],"imports":[{"note":"pytest-flask fixtures like 'app', 'client', 'live_server' are auto-discovered by pytest and typically not imported directly from pytest_flask. You define your 'app' fixture, and then 'client' and 'live_server' use it.","symbol":"app (fixture)","correct":"import pytest\n# @pytest.fixture def app(): ..."},{"note":"Accessed as an argument in your test functions after defining the 'app' fixture.","symbol":"client (fixture)","correct":"def test_something(client): ..."},{"note":"Accessed as an argument in your test functions after defining the 'app' fixture.","symbol":"live_server (fixture)","correct":"def test_live_server_access(live_server): ..."}],"quickstart":{"code":"# myapp.py\nfrom flask import Flask\n\ndef create_app():\n    app = Flask(__name__)\n\n    @app.route('/hello')\n    def hello():\n        return 'Hello, World!'\n\n    return app\n\n# conftest.py\nimport pytest\nfrom myapp import create_app\n\n@pytest.fixture\ndef app():\n    app = create_app()\n    app.config.update({\"TESTING\": True}) # Recommended for testing\n    yield app\n\n@pytest.fixture\ndef client(app):\n    return app.test_client()\n\n# test_app.py\ndef test_hello_world(client):\n    response = client.get('/hello')\n    assert response.status_code == 200\n    assert b'Hello, World!' in response.data\n","lang":"python","description":"To get started, define your Flask application factory in a module (e.g., `myapp.py`), then create a `pytest` fixture named `app` in your `conftest.py` file. This fixture will create and configure your Flask application for testing. The `client` fixture, provided by `pytest-flask`, will then be available in your tests to make requests against your application. Run tests with `pytest`."},"warnings":[{"fix":"Update to pytest-flask 1.3.0+ and refactor tests to not use `request_ctx`. Consider `app.test_request_context()` for manual context manipulation if necessary.","message":"The `request_ctx` fixture was removed in version 1.3.0 due to compatibility changes with Flask 3.0.0. Older versions of pytest-flask using this fixture will be incompatible with Flask 3.0.0+.","severity":"breaking","affected_versions":">=1.3.0 (removal), <1.3.0 (incompatibility with Flask 3.0.0)"},{"fix":"Remove `.url` calls. Construct URLs manually or use `flask.url_for(..., _external=True)` if testing a live server.","message":"The `live_server.url` method was removed in version 1.2.0. Direct access to the live server URL should use string formatting or `flask.url_for` with `_external=True`.","severity":"breaking","affected_versions":">=1.2.0"},{"fix":"If a function-scoped live server is required, configure `live-server_scope = function` in your `pytest.ini` file.","message":"Starting from version 1.0.0, the `live_server` fixture became session-scoped by default. This changes its lifecycle from function-scoped, potentially impacting tests expecting a fresh server for each test function.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Upgrade your Python environment to 3.5 or a later supported version (currently Python >=3.7 is required).","message":"Support for Python 2.7 and 3.4 was dropped in version 1.0.0. Ensure your testing environment uses Python 3.5 or newer.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Always keep `pytest-flask` updated to the latest version to ensure compatibility with recent Flask and Werkzeug releases. If encountering issues, check `pytest-flask`'s GitHub issues for known incompatibilities.","message":"Older versions of `pytest-flask` might encounter incompatibilities with newer versions of Werkzeug (e.g., Werkzeug >=3.1). Check release notes and open issues for specific version requirements.","severity":"gotcha","affected_versions":"<1.3.0 (potentially with Werkzeug >=3.1)"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}