Skip to content

Replace importlib_metadata with importlib.metadata on Python 3.8+ #5539

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

Merged
merged 2 commits into from
Jul 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/5523.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed using multiple short options together in the command-line (for example ``-vs``) in Python 3.8+.
2 changes: 2 additions & 0 deletions changelog/5537.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Replace ``importlib_metadata`` backport with ``importlib.metadata`` from the
standard library on Python 3.8+.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
'pathlib2>=2.2.0;python_version<"3.6"',
'colorama;sys_platform=="win32"',
"pluggy>=0.12,<1.0",
"importlib-metadata>=0.12",
'importlib-metadata>=0.12;python_version<"3.8"',
"wcwidth",
]

Expand Down
6 changes: 6 additions & 0 deletions src/_pytest/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
)


if sys.version_info >= (3, 8):
from importlib import metadata as importlib_metadata # noqa
else:
import importlib_metadata # noqa


def _format_args(func):
return str(signature(func))

Expand Down
2 changes: 1 addition & 1 deletion src/_pytest/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import warnings
from functools import lru_cache

import importlib_metadata
import py
from packaging.version import Version
from pluggy import HookimplMarker
Expand All @@ -25,6 +24,7 @@
from .findpaths import exists
from _pytest._code import ExceptionInfo
from _pytest._code import filter_traceback
from _pytest.compat import importlib_metadata
from _pytest.outcomes import fail
from _pytest.outcomes import Skipped
from _pytest.warning_types import PytestConfigWarning
Expand Down
2 changes: 1 addition & 1 deletion src/_pytest/config/argparsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ def parse_args(self, args=None, namespace=None):
getattr(args, FILE_OR_DIR).extend(argv)
return args

if sys.version_info[:2] < (3, 8): # pragma: no cover
if sys.version_info[:2] < (3, 9): # pragma: no cover
# Backport of https://github.com/python/cpython/pull/14316 so we can
# disable long --argument abbreviations without breaking short flags.
def _parse_optional(self, arg_string):
Expand Down
2 changes: 1 addition & 1 deletion testing/acceptance_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import types

import attr
import importlib_metadata
import py

import pytest
from _pytest.compat import importlib_metadata
from _pytest.main import ExitCode
from _pytest.warnings import SHOW_PYTEST_WARNINGS_ARG

Expand Down
3 changes: 2 additions & 1 deletion testing/test_assertion.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ def check(values, value):
return check
""",
"mainwrapper.py": """\
import pytest, importlib_metadata
import pytest
from _pytest.compat import importlib_metadata

class DummyEntryPoint(object):
name = 'spam'
Expand Down
3 changes: 1 addition & 2 deletions testing/test_config.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import sys
import textwrap

import importlib_metadata

import _pytest._code
import pytest
from _pytest.compat import importlib_metadata
from _pytest.config import _iter_rewritable_modules
from _pytest.config.exceptions import UsageError
from _pytest.config.findpaths import determine_setup
Expand Down
2 changes: 1 addition & 1 deletion testing/test_entry_points.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import importlib_metadata
from _pytest.compat import importlib_metadata


def test_pytest_entry_points_are_identical():
Expand Down