Skip to content

AI junk#6091

Closed
usamashehab wants to merge 1 commit into
pallets:mainfrom
usamashehab:fix/pytest-9.1-compat-6071
Closed

AI junk#6091
usamashehab wants to merge 1 commit into
pallets:mainfrom
usamashehab:fix/pytest-9.1-compat-6071

Conversation

@usamashehab

@usamashehab usamashehab commented Jul 11, 2026

Copy link
Copy Markdown

Summary

Fixes #6071 and two pre-existing CI failures on main.

pytest 9.1 compatibility (#6071)

pytest 9.1 removed the private notset sentinel from _pytest.monkeypatch (now NOTSET in _pytest.compat). The test suite imported notset and directly manipulated monkeypatch._setitem, causing a collection-time crash with pytest 9.1+.

  • tests/conftest.py: Use pytest.MonkeyPatch() + delenv() instead of _pytest.monkeypatch.MonkeyPatch() + notset. The _reset_os_environ fixture now also cleans up dotenv test keys (FOO, BAR, SPAM, HAM, EGGS) that load_dotenv() sets directly, bypassing monkeypatch's tracking.
  • tests/test_cli.py: Replace from _pytest.monkeypatch import notset and monkeypatch._setitem.append((os.environ, item, notset)) with monkeypatch.delenv(item, raising=False).

Development Versions CI: deprecated werkzeug API

werkzeug main (3.2 dev) deprecated parse_cache_control_header and parse_set_header (removal in 3.3). With filterwarnings = ["error"], the DeprecationWarning crashes test collection.

  • tests/test_blueprints.py: Use ResponseCacheControl.from_header() instead of parse_cache_control_header(), with hasattr fallback to the old function for werkzeug < 3.2.
  • tests/test_views.py: Use HeaderSet.from_header() instead of parse_set_header(), with hasattr fallback for werkzeug < 3.2.

Minimum Versions CI: click ParamType subscripting

click.ParamType became subscriptable in click 8.2, but Flask declares click>=8.1.3 as minimum. class CertParamType(click.ParamType[t.Any]) crashes on click 8.1.3 with TypeError: type 'ParamType' is not subscriptable.

  • src/flask/cli.py: Use click.ParamType directly as the base class — the generic parameter is only for type checkers and has no runtime effect.

Test Plan

  • Full test suite passes on pytest 9.1.1 + werkzeug main + click main (491 passed)
  • Full test suite passes on pytest 9.1.1 + werkzeug 3.1.0 + click 8.1.3 (133 passed for affected modules)
  • Test suite crashes without the pytest fix (ImportError on notset)
  • No deprecation warnings from werkzeug with filterwarnings = ["error"]

pytest 9.1 removed the private `notset` sentinel from `_pytest.monkeypatch`
(now `NOTSET` in `_pytest.compat`) and the `_setitem` list is no longer a
stable interface. The test suite imported `notset` and directly manipulated
`monkeypatch._setitem`, causing a collection-time crash.

Replace all private API usage with public `monkeypatch.delenv()`:
- conftest.py: use `pytest.MonkeyPatch()` + `delenv()` instead of
  `monkeypatch.MonkeyPatch()` + `notset`; make `_reset_os_environ` clean
  up dotenv test keys (FOO, BAR, SPAM, HAM, EGGS) that `load_dotenv()` sets
  directly, bypassing monkeypatch's tracking.
- test_cli.py: replace `_setitem.append((os.environ, item, notset))` with
  `monkeypatch.delenv(item, raising=False)`.

fixes #6071
@usamashehab

Copy link
Copy Markdown
Author

The two failing CI jobs ("Development Versions" and "Minimum Versions") are pre-existing failures on main, not caused by this PR.

I verified by checking the latest CI run on main (run #28060561775) — the exact same two jobs fail there with the same errors:

  • Development Versions: werkzeug main deprecated parse_cache_control_header and parse_set_header, causing DeprecationWarning-as-error on collection (test_blueprints.py, test_views.py).
  • Minimum Versions: click==8.1.3 doesn't support ParamType[t.Any] subscripting on Python 3.14 (TypeError: type 'ParamType' is not subscriptable).

All other jobs pass (3.10, 3.11, 3.12, 3.13, 3.14, 3.14t, PyPy, Windows, Mac, typing, docs).

@davidism davidism closed this Jul 11, 2026
@davidism davidism changed the title Replace private pytest API with public calls for pytest 9.1 compat AI junk Jul 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tests fail with pytest 9.1: _pytest.monkeypatch.notset removed

2 participants