pytest-flask icon indicating copy to clipboard operation
pytest-flask copied to clipboard

Incompatibility with `werkzeug>=3.1`

Open stancld opened this issue 1 year ago • 1 comments

Describe the bug Hey, pytest flask fixtures are currently incompatible with the newer werkzeug releases.

self = <FlaskClient <Flask 'click_api.app'>>
args = (<Flask 'click_api.app'>, <class 'pytest_flask.plugin.<class 'pytest_flask.plugin.JSONResponse'>'>)
kwargs = {'use_cookies': True}
    def __init__(self, *args: t.Any, **kwargs: t.Any) -> None:
        super().__init__(*args, **kwargs)
        self.preserve_context = False
        self._new_contexts: t.List[t.ContextManager[t.Any]] = []
        self._context_stack = ExitStack()
        self.environ_base = {
            "REMOTE_ADDR": "127.0.0.1",
>           "HTTP_USER_AGENT": f"werkzeug/{werkzeug.__version__}",
        }
E       AttributeError: module 'werkzeug' has no attribute '__version__'
__class__  = <class 'flask.testing.FlaskClient'>
args       = (<Flask 'click_api.app'>,
 <class 'pytest_flask.plugin.<class 'pytest_flask.plugin.JSONResponse'>'>)
kwargs     = {'use_cookies': True}
self       = <FlaskClient <Flask 'click_api.app'>>
/opt/python/lib/python3.11/site-packages/flask/testing.py:116: AttributeError

To Reproduce Steps to reproduce the behavior:

  1. Start a python container via docker run python:3.11-slim bash
  2. Install necessary dependencies: python -m pip install -U pytest-flask requests werkzeug
  3. Run some tests requiring client fixture. E.g. set up minimalistic app according to the package readme and create a test like that:
@pytest.mark.unit
def werk_test(client):
    assert client

Expected behavior Either compatibility with the newest werkzeug version or pin to an older one.

Environment (please complete the following information):

  • Python Version [e.g. 3.8.5]: 3.11
  • pytest-flask version: 1.3.0
  • werkzeug version: 3.1.3

Thanks a lot! Let me know if I can be any of help.

stancld avatar Nov 14 '24 12:11 stancld

This is not an issue with pytest-flask. It looks like you’re using an outdated version of flask (see https://github.com/pallets/flask/issues/5652). Once you update flask this should work again

geigerzaehler avatar Jan 27 '25 14:01 geigerzaehler