pytest/5539.patch

130 lines
4.0 KiB
Diff
Raw Normal View History

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
---
changelog/5537.bugfix.rst | 2 ++
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
diff --git a/setup.py b/setup.py
index 18d3220..491a6f5 100644
--- a/setup.py
+++ b/setup.py
@@ -15,7 +15,7 @@ INSTALL_REQUIRES = [
'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",
]
diff --git a/src/_pytest/compat.py b/src/_pytest/compat.py
index df661bf..4366391 100644
--- a/src/_pytest/compat.py
+++ b/src/_pytest/compat.py
@@ -61,6 +61,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))
diff --git a/src/_pytest/config/__init__.py b/src/_pytest/config/__init__.py
index 6d44bf3..b35faff 100644
--- a/src/_pytest/config/__init__.py
+++ b/src/_pytest/config/__init__.py
@@ -13,7 +13,6 @@ import sys
import types
import warnings
-import importlib_metadata
import py
import six
from packaging.version import Version
@@ -31,6 +30,7 @@ from .findpaths import exists
from _pytest import deprecated
from _pytest._code import ExceptionInfo
from _pytest._code import filter_traceback
+from _pytest.compat import importlib_metadata
from _pytest.compat import lru_cache
from _pytest.compat import safe_str
from _pytest.outcomes import fail
diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py
index 7016cf1..2e1a3fa 100644
--- a/testing/acceptance_test.py
+++ b/testing/acceptance_test.py
@@ -9,11 +9,11 @@ import textwrap
import types
import attr
-import importlib_metadata
import py
import six
import pytest
+from _pytest.compat import importlib_metadata
from _pytest.main import EXIT_NOTESTSCOLLECTED
from _pytest.main import EXIT_USAGEERROR
from _pytest.warnings import SHOW_PYTEST_WARNINGS_ARG
diff --git a/testing/test_assertion.py b/testing/test_assertion.py
index 2085ffd..61b990a 100644
--- a/testing/test_assertion.py
+++ b/testing/test_assertion.py
@@ -179,7 +179,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'
diff --git a/testing/test_config.py b/testing/test_config.py
index 0678a0d..60cdbaf 100644
--- a/testing/test_config.py
+++ b/testing/test_config.py
@@ -6,10 +6,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.exceptions import UsageError
from _pytest.config.findpaths import determine_setup
diff --git a/testing/test_entry_points.py b/testing/test_entry_points.py
index ad64d00..95ebc41 100644
--- a/testing/test_entry_points.py
+++ b/testing/test_entry_points.py
@@ -3,7 +3,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():