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

Function test_event_postprocessor

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

Source from the content-addressed store, hash-verified

133
134@pytest.mark.anyio
135async def test_event_postprocessor(app: App, monkeypatch: pytest.MonkeyPatch):
136 with monkeypatch.context() as m:
137 m.setattr(message, "_event_postprocessors", set())
138
139 runned = False
140
141 @event_postprocessor
142 async def test_postprocessor(
143 bot: Bot,
144 event: Event,
145 state: T_State,
146 sub: int = Depends(_dependency),
147 default: int = 1,
148 ):
149 nonlocal runned
150 runned = True
151
152 assert test_postprocessor in {
153 dependent.call for dependent in message._event_postprocessors
154 }
155
156 with app.provider.context({}):
157 matcher = on_message()
158
159 async with app.test_matcher(matcher) as ctx:
160 bot = ctx.create_bot()
161 event = make_fake_event()()
162 ctx.receive_event(bot, event)
163
164 assert runned, "event_postprocessor should runned"
165
166
167@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