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

Function test_run_preprocessor_exception

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

Source from the content-addressed store, hash-verified

270
271@pytest.mark.anyio
272async def test_run_preprocessor_exception(
273 app: App, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
274):
275 with monkeypatch.context() as m:
276 m.setattr(message, "_run_preprocessors", set())
277
278 @run_preprocessor
279 async def test_preprocessor():
280 raise RuntimeError("test")
281
282 assert test_preprocessor in {
283 dependent.call for dependent in message._run_preprocessors
284 }
285
286 runned = False
287
288 async def handler():
289 nonlocal runned
290 runned = True
291
292 handler_id = logger.add(
293 sys.stdout,
294 level=0,
295 diagnose=False,
296 filter=default_filter,
297 format=default_format,
298 )
299
300 try:
301 with app.provider.context({}):
302 matcher = on_message(handlers=[handler])
303
304 async with app.test_matcher(matcher) as ctx:
305 bot = ctx.create_bot()
306 event = make_fake_event()()
307 ctx.receive_event(bot, event)
308 finally:
309 logger.remove(handler_id)
310
311 assert not runned, "matcher should not runned"
312 assert "RuntimeError: test" in capsys.readouterr().out
313
314
315@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