From 1db132290f25f53482f8d22db0afd00b8817a9d0 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Sat, 29 Jun 2019 11:13:24 -0300 Subject: [PATCH 1/2] Apply workaround for multiple short options for Python <= 3.8 Hopefully by Python 3.9 this will be fixed upstream, if not we will need to bump the version again. Fix #5523 --- changelog/5523.bugfix.rst | 1 + src/_pytest/config/argparsing.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 changelog/5523.bugfix.rst diff --git a/changelog/5523.bugfix.rst b/changelog/5523.bugfix.rst new file mode 100644 index 000000000..5155b92b1 --- /dev/null +++ b/changelog/5523.bugfix.rst @@ -0,0 +1 @@ +Fixed using multiple short options together in the command-line (for example ``-vs``) in Python 3.8+. diff --git a/src/_pytest/config/argparsing.py b/src/_pytest/config/argparsing.py index d62ed0d03..43cf62ab1 100644 --- a/src/_pytest/config/argparsing.py +++ b/src/_pytest/config/argparsing.py @@ -358,7 +358,7 @@ class MyOptionParser(argparse.ArgumentParser): 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): From c54cbd63c8bc5db6626d26c0f3339a552a6b1a90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Wed, 3 Jul 2019 01:46:44 +0200 Subject: [PATCH 2/2] 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/changelog/5537.bugfix.rst b/changelog/5537.bugfix.rst new file mode 100644 index 000000000..0263e8cdf --- /dev/null +++ b/changelog/5537.bugfix.rst @@ -0,0 +1,2 @@ +Replace ``importlib_metadata`` backport with ``importlib.metadata`` from the +standard library on Python 3.8+. diff --git a/setup.py b/setup.py index 4c87c6429..e8bc8e895 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,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 d238061b4..a83932c88 100644 --- a/src/_pytest/compat.py +++ b/src/_pytest/compat.py @@ -26,6 +26,12 @@ MODULE_NOT_FOUND_ERROR = ( ) +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 c1bd2e7eb..c9310bcb5 100644 --- a/src/_pytest/config/__init__.py +++ b/src/_pytest/config/__init__.py @@ -9,7 +9,6 @@ import types import warnings from functools import lru_cache -import importlib_metadata import py from packaging.version import Version from pluggy import HookimplMarker @@ -25,6 +24,7 @@ from .findpaths import determine_setup 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 diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py index d2a348f40..41de690bc 100644 --- a/testing/acceptance_test.py +++ b/testing/acceptance_test.py @@ -4,10 +4,10 @@ import textwrap 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 diff --git a/testing/test_assertion.py b/testing/test_assertion.py index f58d240a5..8079c45a0 100644 --- a/testing/test_assertion.py +++ b/testing/test_assertion.py @@ -172,7 +172,8 @@ class TestImportHookInstallation: 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 ff993e401..eb7f95271 100644 --- a/testing/test_config.py +++ b/testing/test_config.py @@ -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 diff --git a/testing/test_entry_points.py b/testing/test_entry_points.py index 9812ce998..5d0031273 100644 --- a/testing/test_entry_points.py +++ b/testing/test_entry_points.py @@ -1,4 +1,4 @@ -import importlib_metadata +from _pytest.compat import importlib_metadata def test_pytest_entry_points_are_identical():