diff --git a/.github/workflows/e2e-subtensor-tests.yml b/.github/workflows/e2e-subtensor-tests.yml index 241abdc7..92d4b81b 100644 --- a/.github/workflows/e2e-subtensor-tests.yml +++ b/.github/workflows/e2e-subtensor-tests.yml @@ -81,7 +81,7 @@ jobs: - name: Install uv uses: astral-sh/setup-uv@v4 with: - python-version: 3.13 + python-version: ${{ matrix.python-version }} - name: install dependencies run: | diff --git a/tests/e2e_tests/conftest.py b/tests/e2e_tests/conftest.py index ba2c6c01..a44b67cd 100644 --- a/tests/e2e_tests/conftest.py +++ b/tests/e2e_tests/conftest.py @@ -173,6 +173,7 @@ def try_start_docker(): start_new_session=True, ) as process: try: + loop = None substrate = None try: pattern = re.compile(r"Imported #1") @@ -187,22 +188,29 @@ def try_start_docker(): ) if not result.stdout.strip(): raise RuntimeError("Docker container failed to start.") + + loop = asyncio.new_event_loop() + asyncio.set_event_loop(loop) substrate = AsyncSubstrateInterface(url="ws://127.0.0.1:9944") yield substrate finally: try: - if substrate: - asyncio.run(substrate.close()) + if substrate and loop: + loop.run_until_complete(substrate.close()) except Exception: logging.warning("Failed to close substrate connection.") try: subprocess.run(["docker", "kill", container_name]) + subprocess.run(["docker", "wait", container_name], check=False) process.wait(timeout=10) except subprocess.TimeoutExpired: os.killpg(os.getpgid(process.pid), signal.SIGKILL) + if loop: + loop.close() + @pytest.fixture(scope="function") def wallet_setup(): diff --git a/tests/e2e_tests/test_senate.py b/tests/e2e_tests/test_senate.py index 9a295557..d254df82 100644 --- a/tests/e2e_tests/test_senate.py +++ b/tests/e2e_tests/test_senate.py @@ -10,7 +10,7 @@ import asyncio import json -from .utils import call_add_proposal +from .utils import call_add_proposal, run_async def test_senate(local_chain, wallet_setup): @@ -92,7 +92,7 @@ def test_senate(local_chain, wallet_setup): assert wallet_bob.hotkey.ss58_address in root_senate_after_reg.stdout # Manually add a proposal on the chain & assert - success = asyncio.run(call_add_proposal(local_chain, wallet_bob)) + success = run_async(call_add_proposal(local_chain, wallet_bob)) assert success is True # Fetch proposals after adding one diff --git a/tests/e2e_tests/utils.py b/tests/e2e_tests/utils.py index 07f2fbd9..9a9fec02 100644 --- a/tests/e2e_tests/utils.py +++ b/tests/e2e_tests/utils.py @@ -1,3 +1,4 @@ +import asyncio import os import re import shutil @@ -302,6 +303,16 @@ async def call_add_proposal( return await response.is_success +def run_async(coro): + """Simple helper to run async code in tests (for 3.9).""" + try: + loop = asyncio.get_event_loop() + except RuntimeError: + loop = asyncio.new_event_loop() + asyncio.set_event_loop(loop) + return loop.run_until_complete(coro) + + async def set_storage_extrinsic( substrate: "AsyncSubstrateInterface", wallet: "Wallet",