MCPcopy Create free account
hub / github.com/nonebot/nonebot2 / test_event_postprocessor_exception

Function test_event_postprocessor_exception

tests/test_broadcast.py:168–201  ·  view source on GitHub ↗
(
    app: App, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
)

Source from the content-addressed store, hash-verified

166
167@pytest.mark.anyio
168async def test_event_postprocessor_exception(
169 app: App, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
170):
171 with monkeypatch.context() as m:
172 m.setattr(message, "_event_postprocessors", set())
173
174 @event_postprocessor
175 async def test_postprocessor():
176 raise RuntimeError("test")
177
178 assert test_postprocessor in {
179 dependent.call for dependent in message._event_postprocessors
180 }
181
182 handler_id = logger.add(
183 sys.stdout,
184 level=0,
185 diagnose=False,
186 filter=default_filter,
187 format=default_format,
188 )
189
190 try:
191 with app.provider.context({}):
192 matcher = on_message()
193
194 async with app.test_matcher(matcher) as ctx:
195 bot = ctx.create_bot()
196 event = make_fake_event()()
197 ctx.receive_event(bot, event)
198 finally:
199 logger.remove(handler_id)
200
201 assert "RuntimeError: test" in capsys.readouterr().out
202
203
204@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