public inbox for git-commits@fedoraproject.org
help / color / mirror / Atom feed
To: git-commits@fedoraproject.org
Subject: [rpms/python-flask] rawhide: Backport upstream patch for pytest >= 9.1 compatibility
Date: Mon, 03 Aug 2026 10:52:47 GMT [thread overview]
Message-ID: <178575436722.1.3080458786416208592.rpms-python-flask-755b8cc58a5c@fedoraproject.org> (raw)
A new commit has been pushed.
Repo : rpms/python-flask
Branch : rawhide
Commit : 755b8cc58a5c739a0bc1dd42a53f313424bcd57f
Author : Tomáš Hrnčiar <thrnciar@redhat.com>
Date : 2026-07-29T15:56:06+02:00
Stats : +152/-1 in 2 file(s)
URL : https://src.fedoraproject.org/rpms/python-flask/c/755b8cc58a5c739a0bc1dd42a53f313424bcd57f?branch=rawhide
Log:
Backport upstream patch for pytest >= 9.1 compatibility
---
diff --git a/Replace-the-use-of-private-monkeypatch-fixture-API.patch b/Replace-the-use-of-private-monkeypatch-fixture-API.patch
new file mode 100644
index 0000000..111cd41
--- /dev/null
+++ b/Replace-the-use-of-private-monkeypatch-fixture-API.patch
@@ -0,0 +1,147 @@
+From 14298af058884ebdef4bd28f6cf69f0be4401128 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= <mgorny@gentoo.org>
+Date: Wed, 29 Jul 2026 15:51:04 +0200
+Subject: [PATCH] Replace the use of private monkeypatch fixture API
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+Replace the use of private `monkeypatch` API with the standard
+invocations to fix compatibility with pytest 9.1, as well as to make
+the tests more reliable in the future.
+
+The previous code operated on `monkeypatch` fixture internals to trigger
+clearing environment variables expected by tests at the beginning of
+tests, and reverting any changes made by the tests. However, this does
+not seem strictly valid, and it actually lead to tests making wrong
+assumptions. For example, `test_disable_dotenv_from_env` relied
+on a previous test unsetting `FOO` in the environment, and failed if
+`FOO` was set while it was run alone.
+
+The new logic uses public API only: it cleans up the standard set of
+environment variables for every test, and additionally cleans up
+variables specifically used by dotenv tests. With this approach, it is
+entirely possible for a test to leave the environment "dirty"; however,
+that's fine since other tests need to clean up the environment anyway to
+account for user-set environment variables.
+
+Fixes #6071
+
+Signed-off-by: Michał Górny <mgorny@gentoo.org>
+---
+ tests/conftest.py | 43 +++++++++++++------------------------------
+ tests/test_cli.py | 8 ++++----
+ 2 files changed, 17 insertions(+), 34 deletions(-)
+
+diff --git a/tests/conftest.py b/tests/conftest.py
+index 214f520..60bf5f4 100644
+--- a/tests/conftest.py
++++ b/tests/conftest.py
+@@ -2,43 +2,26 @@ import os
+ import sys
+
+ import pytest
+-from _pytest import monkeypatch
+
+ from flask import Flask
+ from flask.globals import request_ctx
+
+
+-@pytest.fixture(scope="session", autouse=True)
+-def _standard_os_environ():
+- """Set up ``os.environ`` at the start of the test session to have
+- standard values. Returns a list of operations that is used by
+- :func:`._reset_os_environ` after each test.
+- """
+- mp = monkeypatch.MonkeyPatch()
+- out = (
+- (os.environ, "FLASK_ENV_FILE", monkeypatch.notset),
+- (os.environ, "FLASK_APP", monkeypatch.notset),
+- (os.environ, "FLASK_DEBUG", monkeypatch.notset),
+- (os.environ, "FLASK_RUN_FROM_CLI", monkeypatch.notset),
+- (os.environ, "WERKZEUG_RUN_MAIN", monkeypatch.notset),
+- )
+-
+- for _, key, value in out:
+- if value is monkeypatch.notset:
+- mp.delenv(key, False)
+- else:
+- mp.setenv(key, value)
+-
+- yield out
+- mp.undo()
+-
+-
+ @pytest.fixture(autouse=True)
+-def _reset_os_environ(monkeypatch, _standard_os_environ):
+- """Reset ``os.environ`` to the standard environ after each test,
+- in case a test changed something without cleaning up.
++def _standard_os_environ(monkeypatch):
++ """Set up ``os.environ`` at the start of every test to have
++ standard values.
+ """
+- monkeypatch._setitem.extend(_standard_os_environ)
++ for key in (
++ "FLASK_ENV_FILE",
++ "FLASK_APP",
++ "FLASK_DEBUG",
++ "FLASK_RUN_FROM_CLI",
++ "WERKZEUG_RUN_MAIN",
++ ):
++ monkeypatch.delenv(key, False)
++
++ yield
+
+
+ @pytest.fixture
+diff --git a/tests/test_cli.py b/tests/test_cli.py
+index e254c1d..79025dd 100644
+--- a/tests/test_cli.py
++++ b/tests/test_cli.py
+@@ -11,7 +11,6 @@ from pathlib import Path
+
+ import click
+ import pytest
+-from _pytest.monkeypatch import notset
+ from click.testing import CliRunner
+
+ from flask import Blueprint
+@@ -534,9 +533,8 @@ need_dotenv = pytest.mark.skipif(
+
+ @need_dotenv
+ def test_load_dotenv(monkeypatch):
+- # can't use monkeypatch.delitem since the keys don't exist yet
+ for item in ("FOO", "BAR", "SPAM", "HAM"):
+- monkeypatch._setitem.append((os.environ, item, notset))
++ monkeypatch.delenv(item, False)
+
+ monkeypatch.setenv("EGGS", "3")
+ monkeypatch.chdir(test_path)
+@@ -559,7 +557,7 @@ def test_load_dotenv(monkeypatch):
+ @need_dotenv
+ def test_dotenv_path(monkeypatch):
+ for item in ("FOO", "BAR", "EGGS"):
+- monkeypatch._setitem.append((os.environ, item, notset))
++ monkeypatch.delenv(item, False)
+
+ load_dotenv(test_path / ".flaskenv")
+ assert Path.cwd() == cwd
+@@ -567,6 +565,7 @@ def test_dotenv_path(monkeypatch):
+
+
+ def test_dotenv_optional(monkeypatch):
++ monkeypatch.delenv("FOO", False)
+ monkeypatch.setitem(sys.modules, "dotenv", None)
+ monkeypatch.chdir(test_path)
+ load_dotenv()
+@@ -575,6 +574,7 @@ def test_dotenv_optional(monkeypatch):
+
+ @need_dotenv
+ def test_disable_dotenv_from_env(monkeypatch, runner):
++ monkeypatch.delenv("FOO", False)
+ monkeypatch.chdir(test_path)
+ monkeypatch.setitem(os.environ, "FLASK_SKIP_DOTENV", "1")
+ runner.invoke(FlaskGroup())
+--
+2.54.0
+
diff --git a/python-flask.spec b/python-flask.spec
index 89dc3d8..922c625 100644
--- a/python-flask.spec
+++ b/python-flask.spec
@@ -13,6 +13,10 @@ License: BSD-3-Clause
URL: http://flask.pocoo.org/
Source0: %{pypi_source}
+# Compatibility with pytest >= 9.1
+# Upstream PR: https://github.com/pallets/flask/pull/6095
+Patch: Replace-the-use-of-private-monkeypatch-fixture-API.patch
+
BuildArch: noarch
%global _description \
@@ -50,7 +54,7 @@ Documentation and examples for %{name}.
%pyproject_buildrequires -x async -g tests %{?with_doc:-g docs}
%prep
-%autosetup -n %{srcname}-%{version}
+%autosetup -p1 -n %{srcname}-%{version}
# Allow to use python-sphinx>=9
sed -i 's/sphinx<9/sphinx/g' pyproject.toml
reply other threads:[~2026-08-03 10:52 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=178575436722.1.3080458786416208592.rpms-python-flask-755b8cc58a5c@fedoraproject.org \
--to=git-commits@fedoraproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox