From c54cbd63c8bc5db6626d26c0f3339a552a6b1a90 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= <miro@hroncok.cz>
Date: Wed, 3 Jul 2019 01:46:44 +0200
Subject: [PATCH] Replace importlib_metadata with importlib.metadata on Python
 3.8+

Fixes https://github.com/pytest-dev/pytest/issues/5537
---
 setup.py                       | 2 +-
 src/_pytest/compat.py          | 6 ++++++
 src/_pytest/config/__init__.py | 2 +-
 testing/acceptance_test.py     | 2 +-
 testing/test_assertion.py      | 3 ++-
 testing/test_config.py         | 3 +--
 testing/test_entry_points.py   | 2 +-
 8 files changed, 15 insertions(+), 7 deletions(-)
 create mode 100644 changelog/5537.bugfix.rst

Index: pytest-3.10.1/setup.py
===================================================================
--- pytest-3.10.1.orig/setup.py
+++ pytest-3.10.1/setup.py
@@ -15,7 +15,7 @@ INSTALL_REQUIRES = [
     'funcsigs;python_version<"3.0"',
     'pathlib2>=2.2.0;python_version<"3.6"',
     'colorama;sys_platform=="win32"',
-    'importlib-metadata>=0.12',
+    'importlib-metadata>=0.12;python_version<"3.8"',
 ]
 
 
Index: pytest-3.10.1/src/_pytest/compat.py
===================================================================
--- pytest-3.10.1.orig/src/_pytest/compat.py
+++ pytest-3.10.1/src/_pytest/compat.py
@@ -60,6 +60,12 @@ else:
         return None
 
 
+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))
 
Index: pytest-3.10.1/src/_pytest/config/__init__.py
===================================================================
--- pytest-3.10.1.orig/src/_pytest/config/__init__.py
+++ pytest-3.10.1/src/_pytest/config/__init__.py
@@ -12,7 +12,6 @@ import sys
 import types
 import warnings
 
-import importlib_metadata
 import py
 import six
 from packaging.version import Version
@@ -31,6 +30,7 @@ from _pytest._code import ExceptionInfo
 from _pytest._code import filter_traceback
 from _pytest.compat import lru_cache
 from _pytest.compat import safe_str
+from _pytest.compat import importlib_metadata
 from _pytest.outcomes import Skipped
 
 hookimpl = HookimplMarker("pytest")
Index: pytest-3.10.1/testing/acceptance_test.py
===================================================================
--- pytest-3.10.1.orig/testing/acceptance_test.py
+++ pytest-3.10.1/testing/acceptance_test.py
@@ -12,10 +12,10 @@ import py
 import six
 
 import pytest
+from _pytest.compat import importlib_metadata
 from _pytest.main import EXIT_NOTESTSCOLLECTED
 from _pytest.main import EXIT_USAGEERROR
 
-
 def prepend_pythonpath(*dirs):
     cur = os.getenv("PYTHONPATH")
     if cur:
Index: pytest-3.10.1/testing/test_assertion.py
===================================================================
--- pytest-3.10.1.orig/testing/test_assertion.py
+++ pytest-3.10.1/testing/test_assertion.py
@@ -178,7 +178,8 @@ class TestImportHookInstallation(object)
                 return check
             """,
             "mainwrapper.py": """\
-            import pytest, importlib_metadata
+            import pytest
+            from _pytest.compat import importlib_metadata
 
             class DummyEntryPoint(object):
                 name = 'spam'
Index: pytest-3.10.1/testing/test_config.py
===================================================================
--- pytest-3.10.1.orig/testing/test_config.py
+++ pytest-3.10.1/testing/test_config.py
@@ -5,10 +5,9 @@ from __future__ import print_function
 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.findpaths import determine_setup
 from _pytest.config.findpaths import get_common_ancestor
Index: pytest-3.10.1/testing/test_entry_points.py
===================================================================
--- pytest-3.10.1.orig/testing/test_entry_points.py
+++ pytest-3.10.1/testing/test_entry_points.py
@@ -2,7 +2,7 @@ from __future__ import absolute_import
 from __future__ import division
 from __future__ import print_function
 
-import importlib_metadata
+from _pytest.compat import importlib_metadata
 
 
 def test_pytest_entry_points_are_identical():
