diff --git a/AUTHORS b/AUTHORS index 397b896a2..fff3207a3 100644 --- a/AUTHORS +++ b/AUTHORS @@ -146,6 +146,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/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)) 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/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``. 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. 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.