From 0010bfa4bf2bf7680e80de5262de5a37b8ae3150 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Tue, 27 May 2025 21:42:20 +0300 Subject: [PATCH] testing: skip `pkg_resources` tests if modern setuptools setuptools is intending to remove `pkg_resources` at the end of the year. Version 80.9.0 changed the deprecation to a UserMessage which broke the test. Instead of making them compatible, just skip them on versions >= 80 in preparation for the final removal. --- testing/acceptance_test.py | 10 ++++++++-- testing/test_monkeypatch.py | 6 ++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py index 50ea4ff44d2..2d653b8e2a5 100644 --- a/testing/acceptance_test.py +++ b/testing/acceptance_test.py @@ -10,6 +10,8 @@ import sys import types +import setuptools + from _pytest.config import ExitCode from _pytest.pathlib import symlink_or_skip from _pytest.pytester import Pytester @@ -722,10 +724,14 @@ def test_cmdline_python_package(self, pytester: Pytester, monkeypatch) -> None: assert result.ret != 0 result.stderr.fnmatch_lines(["*not*found*test_missing*"]) - def test_cmdline_python_namespace_package( + @pytest.mark.skipif( + int(setuptools.__version__.split(".")[0]) >= 80, + reason="modern setuptools removing pkg_resources", + ) + def test_cmdline_python_legacy_namespace_package( self, pytester: Pytester, monkeypatch ) -> None: - """Test --pyargs option with namespace packages (#1567). + """Test --pyargs option with legacy namespace packages (#1567). Ref: https://packaging.python.org/guides/packaging-namespace-packages/ """ diff --git a/testing/test_monkeypatch.py b/testing/test_monkeypatch.py index ad75273d703..0e992e298ec 100644 --- a/testing/test_monkeypatch.py +++ b/testing/test_monkeypatch.py @@ -8,6 +8,8 @@ import sys import textwrap +import setuptools + from _pytest.monkeypatch import MonkeyPatch from _pytest.pytester import Pytester import pytest @@ -429,6 +431,10 @@ class A: @pytest.mark.filterwarnings(r"ignore:.*\bpkg_resources\b:DeprecationWarning") +@pytest.mark.skipif( + int(setuptools.__version__.split(".")[0]) >= 80, + reason="modern setuptools removing pkg_resources", +) def test_syspath_prepend_with_namespace_packages( pytester: Pytester, monkeypatch: MonkeyPatch ) -> None: