From faded25ee8821fa16b2a31ea65dee49569d158f8 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Thu, 29 Mar 2018 20:02:00 +0200 Subject: [PATCH 1/4] chage collections.abc import to fix deprecation warnings on python 3.7 --- _pytest/assertion/util.py | 6 +++++- _pytest/mark/structures.py | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/_pytest/assertion/util.py b/_pytest/assertion/util.py index 5a380ae09..71ad48251 100644 --- a/_pytest/assertion/util.py +++ b/_pytest/assertion/util.py @@ -5,7 +5,11 @@ import pprint import _pytest._code import py import six -from collections import Sequence +import sys +if sys.version_info >= (3, 4): + from collections.abc import Sequence +else: + from collections import Sequence u = six.text_type diff --git a/_pytest/mark/structures.py b/_pytest/mark/structures.py index c56972980..c52fbd277 100644 --- a/_pytest/mark/structures.py +++ b/_pytest/mark/structures.py @@ -1,4 +1,9 @@ -from collections import namedtuple, MutableMapping as MappingMixin +import sys +if sys.version_info >= (3, 4): + from collections.abc import MutableMapping as MappingMixin +else: + from collections import MutableMapping as MappingMixin +from collections import namedtuple import warnings from operator import attrgetter import inspect From 8ca93219404c92f3f9d080a88e9b6d7642086025 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Thu, 29 Mar 2018 18:54:30 -0300 Subject: [PATCH 2/4] Move compatibility imports to compat.py and fix linting --- _pytest/assertion/util.py | 6 +----- _pytest/compat.py | 8 ++++++++ _pytest/mark/structures.py | 15 +++++---------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/_pytest/assertion/util.py b/_pytest/assertion/util.py index 71ad48251..06d60a6fc 100644 --- a/_pytest/assertion/util.py +++ b/_pytest/assertion/util.py @@ -5,11 +5,7 @@ import pprint import _pytest._code import py import six -import sys -if sys.version_info >= (3, 4): - from collections.abc import Sequence -else: - from collections import Sequence +from ..compat import Sequence u = six.text_type diff --git a/_pytest/compat.py b/_pytest/compat.py index 92df65656..a4ec25212 100644 --- a/_pytest/compat.py +++ b/_pytest/compat.py @@ -38,6 +38,14 @@ PY35 = sys.version_info[:2] >= (3, 5) PY36 = sys.version_info[:2] >= (3, 6) MODULE_NOT_FOUND_ERROR = 'ModuleNotFoundError' if PY36 else 'ImportError' +if _PY2: + # those raise DeprecationWarnings in Python >=3.7 + from collections.abc import MutableMapping as MappingMixin # noqa + from collections.abc import Sequence # noqa +else: + from collections import MutableMapping as MappingMixin # noqa + from collections import Sequence # noqa + def _format_args(func): return str(signature(func)) diff --git a/_pytest/mark/structures.py b/_pytest/mark/structures.py index c52fbd277..a0d4a5ce7 100644 --- a/_pytest/mark/structures.py +++ b/_pytest/mark/structures.py @@ -1,18 +1,13 @@ -import sys -if sys.version_info >= (3, 4): - from collections.abc import MutableMapping as MappingMixin -else: - from collections import MutableMapping as MappingMixin -from collections import namedtuple -import warnings -from operator import attrgetter import inspect +import warnings +from collections import namedtuple +from operator import attrgetter import attr -from ..deprecated import MARK_PARAMETERSET_UNPACKING -from ..compat import NOTSET, getfslineno from six.moves import map +from ..compat import NOTSET, getfslineno, MappingMixin +from ..deprecated import MARK_PARAMETERSET_UNPACKING EMPTY_PARAMETERSET_OPTION = "empty_parameter_set_mark" From 6a81aae4f27d53a0e6006d049bda3c32a255c792 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Thu, 29 Mar 2018 19:04:46 -0300 Subject: [PATCH 3/4] Move compatibility imports to compat.py and fix linting --- changelog/3339.trivial | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog/3339.trivial diff --git a/changelog/3339.trivial b/changelog/3339.trivial new file mode 100644 index 000000000..20196e144 --- /dev/null +++ b/changelog/3339.trivial @@ -0,0 +1 @@ +Import some modules from ``collections`` instead of ``collections.abc`` as the former modules trigger ``DeprecationWarning`` in Python 3.7. From 3fc2c94b5e105421c3d554d92ac07eb289d56289 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Thu, 29 Mar 2018 23:15:03 -0300 Subject: [PATCH 4/4] Switch imports based on python versions, my bad --- _pytest/compat.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/_pytest/compat.py b/_pytest/compat.py index a4ec25212..bcb31cb88 100644 --- a/_pytest/compat.py +++ b/_pytest/compat.py @@ -38,11 +38,11 @@ PY35 = sys.version_info[:2] >= (3, 5) PY36 = sys.version_info[:2] >= (3, 6) MODULE_NOT_FOUND_ERROR = 'ModuleNotFoundError' if PY36 else 'ImportError' -if _PY2: - # those raise DeprecationWarnings in Python >=3.7 +if _PY3: from collections.abc import MutableMapping as MappingMixin # noqa from collections.abc import Sequence # noqa else: + # those raise DeprecationWarnings in Python >=3.7 from collections import MutableMapping as MappingMixin # noqa from collections import Sequence # noqa