Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DeprecationWarning with importlib-metadata>=3.9.0 #333

Closed
domdfcoding opened this issue Apr 1, 2021 · 2 comments · Fixed by #334
Closed

DeprecationWarning with importlib-metadata>=3.9.0 #333

domdfcoding opened this issue Apr 1, 2021 · 2 comments · Fixed by #334

Comments

@domdfcoding
Copy link

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.

@domdfcoding
Copy link
Author

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

@adamchainz
Copy link
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
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants