From 929e7973ce3bb3d39a1e82d5755e15899a12485c Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Wed, 28 May 2025 09:48:23 +0300 Subject: [PATCH] Merge pull request #13444 from pytest-dev/skip-pkg-resources testing: skip `pkg_resources` tests if modern setuptools (cherry picked from commit c7aabccde27f668eca901efa24539c170eb8ab42) --- 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 64a07ba8554..d7ede81340a 100644 --- a/testing/acceptance_test.py +++ b/testing/acceptance_test.py @@ -9,6 +9,8 @@ import sys import types +import setuptools + from _pytest.config import ExitCode from _pytest.pathlib import symlink_or_skip from _pytest.pytester import Pytester @@ -721,10 +723,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 7c62d90f2b9..a7eaee28073 100644 --- a/testing/test_monkeypatch.py +++ b/testing/test_monkeypatch.py @@ -8,6 +8,8 @@ import textwrap from typing import Generator +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: