Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flask v3.0.0 breaks pytest-flask import of _request_ctx_stack #167

Closed
slint opened this issue Oct 2, 2023 · 2 comments · Fixed by #168
Closed

Flask v3.0.0 breaks pytest-flask import of _request_ctx_stack #167

slint opened this issue Oct 2, 2023 · 2 comments · Fixed by #168
Labels

Comments

@slint
Copy link

slint commented Oct 2, 2023

Describe the bug

Flask v3.0.0, released Sep 30th, removed _request_ctx_stack, used in fixtures.py

To Reproduce

  1. Install pytest-flask
  2. Run your tests
  3. See import error
⚠️ Import error stacktrace ⚠️

Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/pytest/__main__.py", line 5, in <module>
    raise SystemExit(pytest.console_main())
  File "/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/_pytest/config/__init__.py", line 187, in console_main
    code = main()
  File "/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/_pytest/config/__init__.py", line 145, in main
    config = _prepareconfig(args, plugins)
  File "/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/_pytest/config/__init__.py", line 324, in _prepareconfig
    config = pluginmanager.hook.pytest_cmdline_parse(
  File "/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/pluggy/_hooks.py", line 493, in __call__
    return self._hookexec(self.name, self._hookimpls, kwargs, firstresult)
  File "/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/pluggy/_manager.py", line [11](https://github.com/zenodo/zenodo-rdm/actions/runs/6382674986/job/17321782664#step:8:12)5, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/pluggy/_callers.py", line 130, in _multicall
    teardown[0].send(outcome)
  File "/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/_pytest/helpconfig.py", line 102, in pytest_cmdline_parse
    config: Config = outcome.get_result()
  File "/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/pluggy/_result.py", line 114, in get_result
    raise exc.with_traceback(exc.__traceback__)
  File "/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/pluggy/_callers.py", line 77, in _multicall
    res = hook_impl.function(*args)
  File "/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/_pytest/config/__init__.py", line 1017, in pytest_cmdline_parse
    self.parse(args)
  File "/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/_pytest/config/__init__.py", line 1305, in parse
    self._preparse(args, addopts=addopts)
  File "/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/_pytest/config/__init__.py", line 1188, in _preparse
    self.pluginmanager.load_setuptools_entrypoints("pytest11")
  File "/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/pluggy/_manager.py", line 398, in load_setuptools_entrypoints
    plugin = ep.load()
  File "/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/importlib/metadata.py", line 86, in load
    module = import_module(match.group('module'))
  File "/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/importlib/__init__.py", line [12](https://github.com/zenodo/zenodo-rdm/actions/runs/6382674986/job/17321782664#step:8:13)7, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/_pytest/assertion/rewrite.py", line 168, in exec_module
    exec(co, module.__dict__)
  File "/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/pytest_invenio/plugin.py", line 25, in <module>
    from .fixtures import (
  File "/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/_pytest/assertion/rewrite.py", line 168, in exec_module
    exec(co, module.__dict__)
  File "/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/pytest_invenio/fixtures.py", line 22, in <module>
    from pytest_flask.plugin import _make_test_response_class
  File "/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/_pytest/assertion/rewrite.py", line 168, in exec_module
    exec(co, module.__dict__)
  File "/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/pytest_flask/plugin.py", line [14](https://github.com/zenodo/zenodo-rdm/actions/runs/6382674986/job/17321782664#step:8:15), in <module>
    from .fixtures import accept_any
  File "/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/_pytest/assertion/rewrite.py", line [16](https://github.com/zenodo/zenodo-rdm/actions/runs/6382674986/job/17321782664#step:8:17)8, in exec_module
    exec(co, module.__dict__)
  File "/opt/hostedtoolcache/Python/3.9.[18](https://github.com/zenodo/zenodo-rdm/actions/runs/6382674986/job/17321782664#step:8:19)/x64/lib/python3.9/site-packages/pytest_flask/fixtures.py", line 6, in <module>
    from flask import _request_ctx_stack
ImportError: cannot import name '_request_ctx_stack' from 'flask' (/opt/hostedtoolcache/Python/3.9.18/x[64](https://github.com/zenodo/zenodo-rdm/actions/runs/6382674986/job/17321782664#step:8:65)/lib/python3.9/site-packages/flask/__init__.py)

Environment (please complete the following information):

  • OS: any
  • Python Version 3.9
  • pytest-flask version 1.2.0

Additional context

It looks like there's a deprecation warning already for using the fixture, so a possible path for a fix would be to:

  1. (Optional) "inline" the import inside the fixture function (to avoid affecting people still using the fixture with Flask <3.0.0, and give them a chance to respond to the deprecation warning).
  2. Remove the fixture completely and release pytest-flask v2.0.0
@slint slint added the bug label Oct 2, 2023
slint added a commit to inveniosoftware/pytest-invenio that referenced this issue Oct 2, 2023
- Temporary pin until pytest-dev/pytest-flask#167 is addressed.
@jonyscathe
Copy link

The request_ctx text fixture has had a deprecation warning on it for about two years.
Should that just be removed at which point request_ctx_stack is no longer needed?

@nicoddemus
Copy link
Member

#168 is open to address this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants