deprecate hook configuration via marks/attributes

fixes #4562
This commit is contained in:
Ronny Pfannschmidt
2021-10-03 16:01:40 +02:00
parent 5bd41befa8
commit 0fdacb6db5
7 changed files with 165 additions and 22 deletions

View File

@@ -20,6 +20,54 @@ def test_external_plugins_integrated(pytester: Pytester, plugin) -> None:
pytester.parseconfig("-p", plugin)
def test_hookspec_via_function_attributes_are_deprecated():
from _pytest.config import PytestPluginManager
pm = PytestPluginManager()
class DeprecatedHookMarkerSpec:
def pytest_bad_hook(self):
pass
pytest_bad_hook.historic = True # type: ignore[attr-defined]
with pytest.warns(
PytestDeprecationWarning,
match=r"Please use the pytest\.hookspec\(historic=True\) decorator",
) as recorder:
pm.add_hookspecs(DeprecatedHookMarkerSpec)
(record,) = recorder
assert (
record.lineno
== DeprecatedHookMarkerSpec.pytest_bad_hook.__code__.co_firstlineno
)
assert record.filename == __file__
def test_hookimpl_via_function_attributes_are_deprecated():
from _pytest.config import PytestPluginManager
pm = PytestPluginManager()
class DeprecatedMarkImplPlugin:
def pytest_runtest_call(self):
pass
pytest_runtest_call.tryfirst = True # type: ignore[attr-defined]
with pytest.warns(
PytestDeprecationWarning,
match=r"Please use the pytest.hookimpl\(tryfirst=True\)",
) as recorder:
pm.register(DeprecatedMarkImplPlugin())
(record,) = recorder
assert (
record.lineno
== DeprecatedMarkImplPlugin.pytest_runtest_call.__code__.co_firstlineno
)
assert record.filename == __file__
def test_fscollector_gethookproxy_isinitpath(pytester: Pytester) -> None:
module = pytester.getmodulecol(
"""