(
app: App, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
)
| 89 | |
| 90 | @pytest.mark.anyio |
| 91 | async def test_event_preprocessor_exception( |
| 92 | app: App, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str] |
| 93 | ): |
| 94 | with monkeypatch.context() as m: |
| 95 | m.setattr(message, "_event_preprocessors", set()) |
| 96 | |
| 97 | @event_preprocessor |
| 98 | async def test_preprocessor(): |
| 99 | raise RuntimeError("test") |
| 100 | |
| 101 | assert test_preprocessor in { |
| 102 | dependent.call for dependent in message._event_preprocessors |
| 103 | } |
| 104 | |
| 105 | runned = False |
| 106 | |
| 107 | async def handler(): |
| 108 | nonlocal runned |
| 109 | runned = True |
| 110 | |
| 111 | handler_id = logger.add( |
| 112 | sys.stdout, |
| 113 | level=0, |
| 114 | diagnose=False, |
| 115 | filter=default_filter, |
| 116 | format=default_format, |
| 117 | ) |
| 118 | |
| 119 | try: |
| 120 | with app.provider.context({}): |
| 121 | matcher = on_message(handlers=[handler]) |
| 122 | |
| 123 | async with app.test_matcher(matcher) as ctx: |
| 124 | bot = ctx.create_bot() |
| 125 | event = make_fake_event()() |
| 126 | ctx.receive_event(bot, event) |
| 127 | finally: |
| 128 | logger.remove(handler_id) |
| 129 | |
| 130 | assert not runned, "matcher should not runned" |
| 131 | assert "RuntimeError: test" in capsys.readouterr().out |
| 132 | |
| 133 | |
| 134 | @pytest.mark.anyio |
nothing calls this directly
no test coverage detected