MCPcopy
hub / github.com/mitmproxy/mitmproxy / test_mixed_async_sync

Function test_mixed_async_sync

test/mitmproxy/test_addonmanager.py:132–154  ·  view source on GitHub ↗
(caplog)

Source from the content-addressed store, hash-verified

130
131
132async def test_mixed_async_sync(caplog):
133 with taddons.context(loadcore=False) as tctx:
134 a = tctx.master.addons
135
136 assert len(a) == 0
137 a1 = TAddon("sync")
138 a2 = AsyncTAddon("async")
139 a.add(a1)
140 a.add(a2)
141
142 # test that we can call both sync and async hooks asynchronously
143 assert not a1.running_called
144 assert not a2.running_called
145 await a.trigger_event(hooks.RunningHook())
146 assert a1.running_called
147 assert a2.running_called
148
149 # test that calling an async hook synchronously fails
150 a1.running_called = False
151 a2.running_called = False
152 a.trigger(hooks.RunningHook())
153 assert a1.running_called
154 assert "called from sync context" in caplog.text
155
156
157async def test_loader(caplog):

Callers

nothing calls this directly

Calls 6

AsyncTAddonClass · 0.85
contextMethod · 0.80
trigger_eventMethod · 0.80
triggerMethod · 0.80
TAddonClass · 0.70
addMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…