From d4065a91668fa5fa3f8ef4b7ae5d2443e78328d7 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Thu, 17 May 2018 20:34:33 -0400 Subject: [PATCH 1/4] Detect `pytest_` prefixed hooks `pluggy` is deprecating the `implprefix` argument in the next major release so implement this detection in our derived plugin manager. Relates to pytest-dev/pluggy#145 --- _pytest/config.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/_pytest/config.py b/_pytest/config.py index eb9c2a1f2..86632ed64 100644 --- a/_pytest/config.py +++ b/_pytest/config.py @@ -177,7 +177,7 @@ class PytestPluginManager(PluginManager): """ def __init__(self): - super(PytestPluginManager, self).__init__("pytest", implprefix="pytest_") + super(PytestPluginManager, self).__init__("pytest") self._conftest_plugins = set() # state related to local conftest plugins @@ -231,6 +231,11 @@ class PytestPluginManager(PluginManager): method = getattr(plugin, name) opts = super(PytestPluginManager, self).parse_hookimpl_opts(plugin, name) + + # collect unmarked hooks as long as they have the `pytest_' prefix + if opts is None and name.startswith("pytest_"): + opts = {} + if opts is not None: for name in ("tryfirst", "trylast", "optionalhook", "hookwrapper"): opts.setdefault(name, hasattr(method, name)) From 486b786cb22e037fc76f210a8c00ab7d42c83a49 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Fri, 18 May 2018 12:02:50 -0400 Subject: [PATCH 2/4] Add trivial changelog entry --- changelog/3487.trivial.rst | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelog/3487.trivial.rst diff --git a/changelog/3487.trivial.rst b/changelog/3487.trivial.rst new file mode 100644 index 000000000..b6dd840f8 --- /dev/null +++ b/changelog/3487.trivial.rst @@ -0,0 +1,3 @@ +Detect `pytest_` prefixed hooks using the internal plugin +manager since ``pluggy`` is deprecating the ``implprefix`` +argument to ``PluginManager``. From f0b855369c5d5163e64f88e8ea3172cfa38de5c8 Mon Sep 17 00:00:00 2001 From: Tim Hughes Date: Sun, 20 May 2018 19:14:06 +0100 Subject: [PATCH 3/4] fix typo --- doc/en/logging.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/en/logging.rst b/doc/en/logging.rst index 44cfaaa28..b2d98f547 100644 --- a/doc/en/logging.rst +++ b/doc/en/logging.rst @@ -123,7 +123,7 @@ You can call ``caplog.clear()`` to reset the captured log records in a test:: assert ['Foo'] == [rec.message for rec in caplog.records] -The ``caplop.records`` attribute contains records from the current stage only, so +The ``caplog.records`` attribute contains records from the current stage only, so inside the ``setup`` phase it contains only setup logs, same with the ``call`` and ``teardown`` phases. From 5072226f69ce7bb2fedd091d3e84cb40fac390ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Tue, 22 May 2018 21:58:31 +0200 Subject: [PATCH 4/4] Import Mapping and Sequence from compat in python_api::approx Related to https://github.com/pytest-dev/pytest/issues/3339 Fixes a DeprecationWarning on Python 3.7 Adds Mapping to compat --- AUTHORS | 1 + _pytest/compat.py | 4 ++-- _pytest/python_api.py | 2 +- changelog/3497.trivial.rst | 5 +++++ 4 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 changelog/3497.trivial.rst diff --git a/AUTHORS b/AUTHORS index 2068a3612..b7765e481 100644 --- a/AUTHORS +++ b/AUTHORS @@ -144,6 +144,7 @@ Michael Seifert Michal Wajszczuk Mihai Capotă Mike Lundy +Miro Hrončok Nathaniel Waisbrot Ned Batchelder Neven Mundar diff --git a/_pytest/compat.py b/_pytest/compat.py index e5c8c3940..abad4f3c5 100644 --- a/_pytest/compat.py +++ b/_pytest/compat.py @@ -40,11 +40,11 @@ MODULE_NOT_FOUND_ERROR = 'ModuleNotFoundError' if PY36 else 'ImportError' if _PY3: from collections.abc import MutableMapping as MappingMixin # noqa - from collections.abc import Sequence # noqa + from collections.abc import Mapping, Sequence # noqa else: # those raise DeprecationWarnings in Python >=3.7 from collections import MutableMapping as MappingMixin # noqa - from collections import Sequence # noqa + from collections import Mapping, Sequence # noqa def _format_args(func): diff --git a/_pytest/python_api.py b/_pytest/python_api.py index 8e09a4a6f..838a4a50c 100644 --- a/_pytest/python_api.py +++ b/_pytest/python_api.py @@ -426,7 +426,7 @@ def approx(expected, rel=None, abs=None, nan_ok=False): __ https://docs.python.org/3/reference/datamodel.html#object.__ge__ """ - from collections import Mapping, Sequence + from _pytest.compat import Mapping, Sequence from _pytest.compat import STRING_TYPES as String from decimal import Decimal diff --git a/changelog/3497.trivial.rst b/changelog/3497.trivial.rst new file mode 100644 index 000000000..c7aca0ec3 --- /dev/null +++ b/changelog/3497.trivial.rst @@ -0,0 +1,5 @@ +Import ``Mapping`` and ``Sequence`` from ``_pytest.compat`` instead of directly +from ``collections`` in ``python_api.py::approx``. Add ``Mapping`` to +``_pytest.compat``, import it from ``collections`` on python 2, but from +``collections.abc`` on Python 3 to avoid a ``DeprecationWarning`` on +Python 3.7 or newer.