-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Closed
Labels
type: selftestsa problem in the tests of pytesta problem in the tests of pytest
Description
This is similar to #10773 - setuptools has added a new warning DeprecationWarning: pkg_resources is deprecated as an API in version 67.5.0 which is hit in addition to the warning that was added in 67.3.0. https://setuptools.pypa.io/en/stable/history.html#v67-5-0
- #3843: Although pkg_resources has been discouraged for use, some projects still consider pkg_resources viable for usage. This change makes it clear that pkg_resources should not be used, emitting a DeprecationWarning when imported.
The same 2 tests fail as in the other issue.
Seen in pytest version 7.2.2, it looks like the issue is also present in the main version.
Note that the other warning that's specifically about pkg_resources.declare_namespace is still present as well, so the pytest self test should ignore both warnings.
test logs
============================================================= FAILURES =============================================================
___________________________________ TestInvocationVariants.test_cmdline_python_namespace_package ___________________________________
self = <acceptance_test.TestInvocationVariants object at 0x7fc0aa9a05b0>
pytester = <Pytester PosixPath('/var/tmp/paludis/build/dev-python-pytest-7.2.2/temp/pytest-of-paludisbuild/pytest-0/test_cmdline_python_namespace_package0')>
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x7fc0a3166400>
def test_cmdline_python_namespace_package(
self, pytester: Pytester, monkeypatch
) -> None:
"""Test --pyargs option with namespace packages (#1567).
Ref: https://packaging.python.org/guides/packaging-namespace-packages/
"""
monkeypatch.delenv("PYTHONDONTWRITEBYTECODE", raising=False)
search_path = []
for dirname in "hello", "world":
d = pytester.mkdir(dirname)
search_path.append(d)
ns = d.joinpath("ns_pkg")
ns.mkdir()
ns.joinpath("__init__.py").write_text(
"__import__('pkg_resources').declare_namespace(__name__)"
)
lib = ns.joinpath(dirname)
lib.mkdir()
lib.joinpath("__init__.py").touch()
lib.joinpath(f"test_{dirname}.py").write_text(
f"def test_{dirname}(): pass\ndef test_other():pass"
)
# The structure of the test directory is now:
# .
# ├── hello
# │ └── ns_pkg
# │ ├── __init__.py
# │ └── hello
# │ ├── __init__.py
# │ └── test_hello.py
# └── world
# └── ns_pkg
# ├── __init__.py
# └── world
# ├── __init__.py
# └── test_world.py
# NOTE: the different/reversed ordering is intentional here.
monkeypatch.setenv("PYTHONPATH", prepend_pythonpath(*search_path))
for p in search_path:
monkeypatch.syspath_prepend(p)
# mixed module and filenames:
monkeypatch.chdir("world")
# pgk_resources.declare_namespace has been deprecated in favor of implicit namespace packages.
# While we could change the test to use implicit namespace packages, seems better
# to still ensure the old declaration via declare_namespace still works.
ignore_w = r"-Wignore:Deprecated call to `pkg_resources.declare_namespace"
result = pytester.runpytest(
"--pyargs", "-v", "ns_pkg.hello", "ns_pkg/world", ignore_w
)
assert result.ret == 0
> result.stdout.fnmatch_lines(
[
"test_hello.py::test_hello*PASSED*",
"test_hello.py::test_other*PASSED*",
"ns_pkg/world/test_world.py::test_world*PASSED*",
"ns_pkg/world/test_world.py::test_other*PASSED*",
"*4 passed in*",
]
)
E Failed: nomatch: 'test_hello.py::test_hello*PASSED*'
E and: '======================================================= test session starts ========================================================'
E and: 'platform linux -- Python 3.8.15, pytest-7.2.2, pluggy-1.0.0 -- /usr/bin/python3.8'
E and: 'cachedir: .pytest_cache'
E and: 'rootdir: /var/tmp/paludis/build/dev-python-pytest-7.2.2/temp/pytest-of-paludisbuild/pytest-0/test_cmdline_python_namespace_package0/world'
E and: 'collecting ... collected 4 items'
E and: ''
E fnmatch: 'test_hello.py::test_hello*PASSED*'
E with: 'test_hello.py::test_hello PASSED [ 25%]'
E fnmatch: 'test_hello.py::test_other*PASSED*'
E with: 'test_hello.py::test_other PASSED [ 50%]'
E fnmatch: 'ns_pkg/world/test_world.py::test_world*PASSED*'
E with: 'ns_pkg/world/test_world.py::test_world PASSED [ 75%]'
E fnmatch: 'ns_pkg/world/test_world.py::test_other*PASSED*'
E with: 'ns_pkg/world/test_world.py::test_other PASSED [100%]'
E nomatch: '*4 passed in*'
E and: ''
E and: '========================================================= warnings summary ========================================================='
E and: '../../../../../../../../../../usr/lib/python3.8/site-packages/pkg_resources/__init__.py:121'
E and: ' /usr/lib/python3.8/site-packages/pkg_resources/__init__.py:121: DeprecationWarning: pkg_resources is deprecated as an API'
E and: ' warnings.warn("pkg_resources is deprecated as an API", DeprecationWarning)'
E and: ''
E and: '-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html'
E and: '=================================================== 4 passed, 1 warning in 0.07s ==================================================='
E remains unmatched: '*4 passed in*'
/var/tmp/paludis/build/dev-python-pytest-7.2.2/work/PYTHON_ABIS/3.8/pytest-7.2.2/testing/acceptance_test.py:706: Failed
------------------------------------------------------- Captured stdout call -------------------------------------------------------
======================================================= test session starts ========================================================
platform linux -- Python 3.8.15, pytest-7.2.2, pluggy-1.0.0 -- /usr/bin/python3.8
cachedir: .pytest_cache
rootdir: /var/tmp/paludis/build/dev-python-pytest-7.2.2/temp/pytest-of-paludisbuild/pytest-0/test_cmdline_python_namespace_package0/world
collecting ... collected 4 items
test_hello.py::test_hello PASSED [ 25%]
test_hello.py::test_other PASSED [ 50%]
ns_pkg/world/test_world.py::test_world PASSED [ 75%]
ns_pkg/world/test_world.py::test_other PASSED [100%]
========================================================= warnings summary =========================================================
../../../../../../../../../../usr/lib/python3.8/site-packages/pkg_resources/__init__.py:121
/usr/lib/python3.8/site-packages/pkg_resources/__init__.py:121: DeprecationWarning: pkg_resources is deprecated as an API
warnings.warn("pkg_resources is deprecated as an API", DeprecationWarning)
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=================================================== 4 passed, 1 warning in 0.07s ===================================================
___________________________________________ test_syspath_prepend_with_namespace_packages ___________________________________________
pytester = <Pytester PosixPath('/var/tmp/paludis/build/dev-python-pytest-7.2.2/temp/pytest-of-paludisbuild/pytest-0/test_syspath_prepend_with_namespace_packages0')>
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x7fc0a2ac3250>
@pytest.mark.filterwarnings(
"ignore:Deprecated call to `pkg_resources.declare_namespace"
)
def test_syspath_prepend_with_namespace_packages(
pytester: Pytester, monkeypatch: MonkeyPatch
) -> None:
for dirname in "hello", "world":
d = pytester.mkdir(dirname)
ns = d.joinpath("ns_pkg")
ns.mkdir()
ns.joinpath("__init__.py").write_text(
"__import__('pkg_resources').declare_namespace(__name__)"
)
lib = ns.joinpath(dirname)
lib.mkdir()
lib.joinpath("__init__.py").write_text("def check(): return %r" % dirname)
monkeypatch.syspath_prepend("hello")
> import ns_pkg.hello
/var/tmp/paludis/build/dev-python-pytest-7.2.2/work/PYTHON_ABIS/3.8/pytest-7.2.2/testing/test_monkeypatch.py:446:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/var/tmp/paludis/build/dev-python-pytest-7.2.2/temp/pytest-of-paludisbuild/pytest-0/test_syspath_prepend_with_namespace_packages0/hello/ns_pkg/__init__.py:1: in <module>
__import__('pkg_resources').declare_namespace(__name__)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
Package resource API
--------------------
A resource is a logical file contained within a package, or a logical
subdirectory thereof. The package resource API expects resource names
to have their path parts separated with ``/``, *not* whatever the local
path separator is. Do not use os.path operations to manipulate resource
names being passed into the API.
The package resource API is designed to work with normal filesystem packages,
.egg files, and unpacked .egg files. It can also work in a limited way with
.zip files and with custom PEP 302 loaders that support the ``get_data()``
method.
This module is deprecated. Users are directed to
`importlib.resources <https://docs.python.org/3/library/importlib.resources.html>`_
and
`importlib.metadata <https://docs.python.org/3/library/importlib.metadata.html>`_
instead.
"""
import sys
import os
import io
import time
import re
import types
import zipfile
import zipimport
import warnings
import stat
import functools
import pkgutil
import operator
import platform
import collections
import plistlib
import email.parser
import errno
import tempfile
import textwrap
import inspect
import ntpath
import posixpath
import importlib
from pkgutil import get_importer
try:
import _imp
except ImportError:
# Python 3.2 compatibility
import imp as _imp
try:
FileExistsError
except NameError:
FileExistsError = OSError
# capture these to bypass sandboxing
from os import utime
try:
from os import mkdir, rename, unlink
WRITE_SUPPORT = True
except ImportError:
# no write support, probably under GAE
WRITE_SUPPORT = False
from os import open as os_open
from os.path import isdir, split
try:
import importlib.machinery as importlib_machinery
# access attribute to force import under delayed import mechanisms.
importlib_machinery.__name__
except ImportError:
importlib_machinery = None
from pkg_resources.extern.jaraco.text import (
yield_lines,
drop_comment,
join_continuation,
)
from pkg_resources.extern import platformdirs
from pkg_resources.extern import packaging
__import__('pkg_resources.extern.packaging.version')
__import__('pkg_resources.extern.packaging.specifiers')
__import__('pkg_resources.extern.packaging.requirements')
__import__('pkg_resources.extern.packaging.markers')
__import__('pkg_resources.extern.packaging.utils')
if sys.version_info < (3, 5):
raise RuntimeError("Python 3.5 or later is required")
# declare some globals that will be defined later to
# satisfy the linters.
require = None
working_set = None
add_activation_listener = None
resources_stream = None
cleanup_resources = None
resource_dir = None
resource_stream = None
set_extraction_path = None
resource_isdir = None
resource_string = None
iter_entry_points = None
resource_listdir = None
resource_filename = None
resource_exists = None
_distribution_finders = None
_namespace_handlers = None
_namespace_packages = None
> warnings.warn("pkg_resources is deprecated as an API", DeprecationWarning)
E DeprecationWarning: pkg_resources is deprecated as an API
/usr/lib/python3.8/site-packages/pkg_resources/__init__.py:121: DeprecationWarning
===================================================== short test summary info ======================================================
FAILED testing/acceptance_test.py::TestInvocationVariants::test_cmdline_python_namespace_package - Failed: nomatch: 'test_hello.py::test_hello*PASSED*'
FAILED testing/test_monkeypatch.py::test_syspath_prepend_with_namespace_packages - DeprecationWarning: pkg_resources is deprecated as an API
Metadata
Metadata
Assignees
Labels
type: selftestsa problem in the tests of pytesta problem in the tests of pytest