Skip to content

AI junk#6099

Closed
eeshsaxena wants to merge 1 commit into
pallets:mainfrom
eeshsaxena:fix/pytest-91-remove-private-notset
Closed

AI junk#6099
eeshsaxena wants to merge 1 commit into
pallets:mainfrom
eeshsaxena:fix/pytest-91-remove-private-notset

Conversation

@eeshsaxena

Copy link
Copy Markdown

Fixes #6071.

The test suite imports
otset\ from _pytest.monkeypatch\ in two places and also pokes the private _setitem\ list directly. pytest 9.1 removed
otset\ from that module, which causes a collection-time crash before any test can run.

Both usages only needed the sentinel to mean 'delete this env var'. \monkeypatch.delenv(key, raising=False)\ does exactly the same thing using the stable public API, so the sentinel is not needed at all.

tests/conftest.py

  • Drop \ rom _pytest import monkeypatch.
  • Replace the
    otset\ tuple with a plain tuple of key names (_FLASK_ENV_KEYS).
  • Use \pytest.MonkeyPatch()\ directly (public class, available since pytest 6.0).
  • _reset_os_environ\ now calls \monkeypatch.delenv(key, raising=False)\ per key instead of appending to the private _setitem\ list.

tests/test_cli.py

  • Remove \ rom _pytest.monkeypatch import notset.
  • Replace \monkeypatch._setitem.append((os.environ, item, notset))\ with \monkeypatch.delenv(item, raising=False)\ in \ est_load_dotenv\ and \ est_dotenv_path. The old comment '# can't use monkeypatch.delitem since the keys don't exist yet' no longer applies — \delenv(raising=False)\ handles missing keys fine.

pytest 9.1 removed the notset sentinel from _pytest.monkeypatch, moving
it to _pytest.compat.NOTSET (a private location). Importing from either
private path breaks on pytest 9.1+.

Both usages only needed notset to signal 'delete this env var before the
test runs'. monkeypatch.delenv(key, raising=False) does exactly that using
the stable public API, so drop the sentinel entirely.

tests/conftest.py:
- Remove 'from _pytest import monkeypatch' import.
- Replace notset sentinel tuple with a plain tuple of key names.
- Use pytest.MonkeyPatch() directly (public class).
- _reset_os_environ now calls monkeypatch.delenv() per key instead of
  appending to the private _setitem list.

tests/test_cli.py:
- Remove 'from _pytest.monkeypatch import notset'.
- Replace _setitem.append(..., notset) with monkeypatch.delenv(raising=False)
  in test_load_dotenv and test_dotenv_path.

Fixes #6071
@davidism davidism closed this Jul 20, 2026
@davidism davidism changed the title tests: replace private _pytest.monkeypatch.notset with public delenv API (fixes pytest 9.1 crash) AI junk Jul 20, 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