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

Function test_run_postprocessor_exception

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

Source from the content-addressed store, hash-verified

352
353@pytest.mark.anyio
354async def test_run_postprocessor_exception(
355 app: App, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
356):
357 with monkeypatch.context() as m:
358 m.setattr(message, "_run_postprocessors", set())
359
360 @run_postprocessor
361 async def test_postprocessor():
362 raise RuntimeError("test")
363
364 assert test_postprocessor in {
365 dependent.call for dependent in message._run_postprocessors
366 }
367
368 handler_id = logger.add(
369 sys.stdout,
370 level=0,
371 diagnose=False,
372 filter=default_filter,
373 format=default_format,
374 )
375
376 try:
377 with app.provider.context({}):
378 matcher = on_message()
379
380 async with app.test_matcher(matcher) as ctx:
381 bot = ctx.create_bot()
382 event = make_fake_event()()
383 ctx.receive_event(bot, event)
384 finally:
385 logger.remove(handler_id)
386
387 assert "RuntimeError: test" in capsys.readouterr().out

Callers

nothing calls this directly

Calls 2

on_messageFunction · 0.90
make_fake_eventFunction · 0.90

Tested by

no test coverage detected