Skip to content

CI/CD: use matrix's python-version #403

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/e2e-subtensor-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
12 changes: 10 additions & 2 deletions tests/e2e_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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():
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e_tests/test_senate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions tests/e2e_tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import asyncio
import os
import re
import shutil
Expand Down Expand Up @@ -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",
Expand Down
Loading