1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
from pathlib import Path
import pytest
from pluggy import HookimplMarker
from pluggy import HookspecMarker
from pluggy import PluggyTeardownRaisedWarning
from pluggy import PluginManager
hookspec = HookspecMarker("example")
hookimpl = HookimplMarker("example")
def test_teardown_raised_warning(pm: PluginManager) -> None:
class Api:
@hookspec
def my_hook(self):
raise NotImplementedError()
pm.add_hookspecs(Api)
class Plugin1:
@hookimpl
def my_hook(self):
pass
class Plugin2:
@hookimpl(hookwrapper=True)
def my_hook(self):
yield
1 / 0
class Plugin3:
@hookimpl(hookwrapper=True)
def my_hook(self):
yield
pm.register(Plugin1(), "plugin1")
pm.register(Plugin2(), "plugin2")
pm.register(Plugin3(), "plugin3")
with pytest.warns(
PluggyTeardownRaisedWarning,
match=r"\bplugin2\b.*\bmy_hook\b.*\n.*ZeroDivisionError",
) as wc:
with pytest.raises(ZeroDivisionError):
pm.hook.my_hook()
assert len(wc.list) == 1
assert Path(wc.list[0].filename).name == "test_warnings.py"
|