MCPcopy
hub / github.com/nonebot/nonebot2 / test_event_preprocessor

Function test_event_preprocessor

tests/test_broadcast.py:28–57  ·  view source on GitHub ↗
(app: App, monkeypatch: pytest.MonkeyPatch)

Source from the content-addressed store, hash-verified

26
27@pytest.mark.anyio
28async def test_event_preprocessor(app: App, monkeypatch: pytest.MonkeyPatch):
29 with monkeypatch.context() as m:
30 m.setattr(message, "_event_preprocessors", set())
31
32 runned = False
33
34 @event_preprocessor
35 async def test_preprocessor(
36 bot: Bot,
37 event: Event,
38 state: T_State,
39 sub: int = Depends(_dependency),
40 default: int = 1,
41 ):
42 nonlocal runned
43 runned = True
44
45 assert test_preprocessor in {
46 dependent.call for dependent in message._event_preprocessors
47 }
48
49 with app.provider.context({}):
50 matcher = on_message()
51
52 async with app.test_matcher(matcher) as ctx:
53 bot = ctx.create_bot()
54 event = make_fake_event()()
55 ctx.receive_event(bot, event)
56
57 assert runned, "event_preprocessor should runned"
58
59
60@pytest.mark.anyio

Callers

nothing calls this directly

Calls 2

on_messageFunction · 0.90
make_fake_eventFunction · 0.90

Tested by

no test coverage detected