Skip to content

Commit 0e47178

Browse files
committed
Add a test.
1 parent 1ac565b commit 0e47178

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Lib/test/test_monitoring.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2083,6 +2083,29 @@ def callback(code, instruction_offset):
20832083
sys.monitoring.restart_events()
20842084
sys.monitoring.set_events(0, 0)
20852085

2086+
def test_yield_async_generator(self):
2087+
# gh-129013: Async generators have a special type that they
2088+
# use to yield values. This type shouldn't be exposed by PY_YIELD
2089+
# events.
2090+
asyncio = test.support.import_helper.import_module("asyncio")
2091+
2092+
async def gen():
2093+
yield 42
2094+
2095+
async def main():
2096+
async for _ in gen():
2097+
pass
2098+
2099+
def handle_yield(code, offset, value):
2100+
self.assertEqual(value, 42)
2101+
2102+
sys.monitoring.use_tool_id(0, "test")
2103+
sys.monitoring.register_callback(0, sys.monitoring.events.PY_YIELD, handle_yield)
2104+
sys.monitoring.set_events(0, sys.monitoring.events.PY_YIELD)
2105+
2106+
asyncio.run(main())
2107+
sys.monitoring.set_events(0, 0)
2108+
20862109

20872110
class TestOptimizer(MonitoringTestBase, unittest.TestCase):
20882111

@@ -2329,3 +2352,6 @@ def test_enter_scope_two_events(self):
23292352

23302353
finally:
23312354
sys.monitoring.set_events(TEST_TOOL, 0)
2355+
2356+
if __name__ == "__main__":
2357+
unittest.main()

0 commit comments

Comments
 (0)