Skip to content

DeprecationWarning with importlib-metadata>=3.9.0 #333

Closed

Description

@domdfcoding

importlib-metadata 3.6.0 changed the behaviour of entry_points() to no longer return a dictionary of entry points but instead return an object with a deprecated dict-like interface. As of importlib-metadata 3.9.0 a DeprecationWarning is emitted when calling the dictionary methods.

pytest-randomly calls .get() here:

if entrypoint_reseeds is None:
entrypoint_reseeds = [
e.load() for e in entry_points().get("pytest_randomly.random_seeder", [])
]
for reseed in entrypoint_reseeds:
reseed(seed)

This results in the following warning:

venv/lib/python3.7/site-packages/pytest_randomly.py:153: DeprecationWarning: SelectableGroups dict interface is deprecated. Use select.
  e.load() for e in entry_points().get("pytest_randomly.random_seeder", [])

If warnings are turned into errors, this causes an internal error in pytest.

INTERNALERROR
(venv) domdf@ryzen:/tmp/pytest_randomly_deprecation$ PYTHONDEVMODE=1 PYTHONWARNINGS=error pytest test_foo.py
============================================================================================ test session starts ============================================================================================
platform linux -- Python 3.7.10, pytest-6.2.2, py-1.10.0, pluggy-0.13.1
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/tmp/pytest_randomly_deprecation/venv/lib/python3.7/site-packages/_pytest/main.py", line 267, in wrap_session
INTERNALERROR>     config.hook.pytest_sessionstart(session=session)
INTERNALERROR>   File "/tmp/pytest_randomly_deprecation/venv/lib/python3.7/site-packages/pluggy/hooks.py", line 286, in __call__
INTERNALERROR>     return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR>   File "/tmp/pytest_randomly_deprecation/venv/lib/python3.7/site-packages/pluggy/manager.py", line 93, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/tmp/pytest_randomly_deprecation/venv/lib/python3.7/site-packages/pluggy/manager.py", line 87, in <lambda>
INTERNALERROR>     firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
INTERNALERROR>   File "/tmp/pytest_randomly_deprecation/venv/lib/python3.7/site-packages/pluggy/callers.py", line 208, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/tmp/pytest_randomly_deprecation/venv/lib/python3.7/site-packages/pluggy/callers.py", line 80, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/tmp/pytest_randomly_deprecation/venv/lib/python3.7/site-packages/pluggy/callers.py", line 187, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/tmp/pytest_randomly_deprecation/venv/lib/python3.7/site-packages/_pytest/terminal.py", line 713, in pytest_sessionstart
INTERNALERROR>     config=self.config, startdir=self.startdir
INTERNALERROR>   File "/tmp/pytest_randomly_deprecation/venv/lib/python3.7/site-packages/pluggy/hooks.py", line 286, in __call__
INTERNALERROR>     return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR>   File "/tmp/pytest_randomly_deprecation/venv/lib/python3.7/site-packages/pluggy/manager.py", line 93, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/tmp/pytest_randomly_deprecation/venv/lib/python3.7/site-packages/pluggy/manager.py", line 87, in <lambda>
INTERNALERROR>     firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
INTERNALERROR>   File "/tmp/pytest_randomly_deprecation/venv/lib/python3.7/site-packages/pluggy/callers.py", line 208, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/tmp/pytest_randomly_deprecation/venv/lib/python3.7/site-packages/pluggy/callers.py", line 80, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/tmp/pytest_randomly_deprecation/venv/lib/python3.7/site-packages/pluggy/callers.py", line 187, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/tmp/pytest_randomly_deprecation/venv/lib/python3.7/site-packages/pytest_randomly.py", line 170, in pytest_report_header
INTERNALERROR>     _reseed(config)
INTERNALERROR>   File "/tmp/pytest_randomly_deprecation/venv/lib/python3.7/site-packages/pytest_randomly.py", line 153, in _reseed
INTERNALERROR>     e.load() for e in entry_points().get("pytest_randomly.random_seeder", [])
INTERNALERROR>   File "/tmp/pytest_randomly_deprecation/venv/lib/python3.7/site-packages/importlib_metadata/__init__.py", line 302, in get
INTERNALERROR>     flake8_bypass(self._warn)()
INTERNALERROR> DeprecationWarning: SelectableGroups dict interface is deprecated. Use select.

See python/importlib_metadata#278 and python/importlib_metadata#289 for more context.

This is currently only an issue on Python 3.7 and earlier, as pytest-randomly uses the standard library on newer versions.

Activity

  1. domdfcoding commented on Apr 1, 2021

    @domdfcoding
    Author

    The changelog suggests https://pypi.org/project/backports.entry-points-selectable/ as a possible solution.

  2. added a commit that references this issue on Apr 1, 2021
    e8bb204
  3. added a commit that references this issue on Apr 1, 2021
    ef72a3f
  4. adamchainz commented on Apr 1, 2021

    @adamchainz
    Member

    Fix released in version 3.6.0, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions