commit:     fcca491b9ad76cda470f80c647bf2d3576583e5f
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Sat Nov 25 11:09:56 2023 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Sat Nov 25 11:14:21 2023 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=fcca491b

dev-python/pytest: Fix running tests with NO_COLOR set

Signed-off-by: Michał Górny <mgorny <AT> gentoo.org>

 .../pytest/files/pytest-7.4.3-no-color.patch       | 37 ++++++++++++++++++++++
 dev-python/pytest/pytest-7.4.3.ebuild              |  5 +++
 2 files changed, 42 insertions(+)

diff --git a/dev-python/pytest/files/pytest-7.4.3-no-color.patch 
b/dev-python/pytest/files/pytest-7.4.3-no-color.patch
new file mode 100644
index 000000000000..a6fa02472252
--- /dev/null
+++ b/dev-python/pytest/files/pytest-7.4.3-no-color.patch
@@ -0,0 +1,37 @@
+From ce93a8ad7a11d1e9be76ce6af0d510f935622c1f Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= <[email protected]>
+Date: Sat, 25 Nov 2023 12:09:32 +0100
+Subject: [PATCH] Reset color-related envvars for testing
+
+Reset color-related environment variables in a fixture to prevent them
+from affecting test results.  Otherwise, some of the tests fail
+e.g. if NO_COLOR is set in the calling environment.
+---
+ testing/conftest.py | 11 +++++++++++
+ 1 file changed, 11 insertions(+)
+
+diff --git a/testing/conftest.py b/testing/conftest.py
+index 2a3ce5203..612777304 100644
+--- a/testing/conftest.py
++++ b/testing/conftest.py
+@@ -30,6 +30,17 @@ def set_column_width(monkeypatch: pytest.MonkeyPatch) -> 
None:
+     monkeypatch.setenv("COLUMNS", "80")
+ 
+ 
[email protected](autouse=True)
++def reset_colors(monkeypatch: pytest.MonkeyPatch) -> None:
++    """
++    Reset all color-related variables to prevent them from affecting internal 
pytest output
++    in tests that depend on it.
++    """
++    monkeypatch.delenv("PY_COLORS", raising=False)
++    monkeypatch.delenv("NO_COLOR", raising=False)
++    monkeypatch.delenv("FORCE_COLOR", raising=False)
++
++
+ @pytest.hookimpl(hookwrapper=True, tryfirst=True)
+ def pytest_collection_modifyitems(items):
+     """Prefer faster tests.
+-- 
+2.43.0
+

diff --git a/dev-python/pytest/pytest-7.4.3.ebuild 
b/dev-python/pytest/pytest-7.4.3.ebuild
index 34cc63f9e938..55eb8e448514 100644
--- a/dev-python/pytest/pytest-7.4.3.ebuild
+++ b/dev-python/pytest/pytest-7.4.3.ebuild
@@ -49,6 +49,11 @@ BDEPEND="
        )
 "
 
+PATCHES=(
+       # https://github.com/pytest-dev/pytest/pull/11638
+       "${FILESDIR}/${P}-no-color.patch"
+)
+
 src_test() {
        # workaround new readline defaults
        echo "set enable-bracketed-paste off" > "${T}"/inputrc || die

Reply via email to