| 600 | queue = asyncio.Queue() |
| 601 | |
| 602 | async def run_pytest_subprocess(): |
| 603 | cmd_args = [ |
| 604 | sys.executable, |
| 605 | "-m", |
| 606 | "pytest", |
| 607 | os.path.join(os.path.dirname(__file__), "agent_test_runner.py"), |
| 608 | "-s", |
| 609 | "-vv", |
| 610 | ] |
| 611 | if test_name: |
| 612 | name_to_use = ( |
| 613 | test_name[:-5] if test_name.endswith(".json") else test_name |
| 614 | ) |
| 615 | cmd_args.extend(["-k", name_to_use]) |
| 616 | |
| 617 | # Ensure environment variable is set |
| 618 | env = os.environ.copy() |
| 619 | env["ADK_TEST_FOLDER"] = agent_dir |
| 620 | |
| 621 | try: |
| 622 | process = await asyncio.create_subprocess_exec( |
| 623 | *cmd_args, |
| 624 | stdout=subprocess.PIPE, |
| 625 | stderr=subprocess.STDOUT, |
| 626 | env=env, |
| 627 | ) |
| 628 | |
| 629 | while True: |
| 630 | line = await process.stdout.readline() |
| 631 | if not line: |
| 632 | break |
| 633 | await queue.put(line.decode("utf-8")) |
| 634 | |
| 635 | await process.wait() |
| 636 | finally: |
| 637 | # Signal completion to generator |
| 638 | await queue.put(None) |
| 639 | |
| 640 | # Start pytest in a background task |
| 641 | asyncio.create_task(run_pytest_subprocess()) |