From 59ae93041158076212e922aecb9ba94b4602c6b2 Mon Sep 17 00:00:00 2001 From: aitbc Date: Sun, 19 Apr 2026 20:44:42 +0200 Subject: [PATCH] refactor: replace hardcoded paths with dynamic Path resolution in staking tests - Changed from hardcoded /opt/aitbc paths to Path(__file__).resolve().parents[2] for dynamic repository root resolution - Reorganized imports to follow standard order (stdlib, third-party, local) - Removed duplicate sys import in test_staking_service.py - Extracted repo_root variable in test_staking_lifecycle.py for cleaner path construction --- tests/fixtures/staking_fixtures.py | 6 ++++-- tests/integration/test_staking_lifecycle.py | 9 ++++++--- tests/services/test_staking_service.py | 7 ++++--- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/tests/fixtures/staking_fixtures.py b/tests/fixtures/staking_fixtures.py index c1154323..9743223d 100644 --- a/tests/fixtures/staking_fixtures.py +++ b/tests/fixtures/staking_fixtures.py @@ -3,15 +3,17 @@ Shared fixtures for staking tests Reusable fixtures for service and integration tests to avoid duplication """ -import pytest import sys +from pathlib import Path from datetime import datetime, timedelta + +import pytest from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker, Session from sqlmodel import SQLModel # Add paths for imports -sys.path.insert(0, "/opt/aitbc/apps/coordinator-api/src") +sys.path.insert(0, str(Path(__file__).resolve().parents[2] / "apps/coordinator-api/src")) from app.domain.bounty import ( AgentStake, AgentMetrics, StakingPool, diff --git a/tests/integration/test_staking_lifecycle.py b/tests/integration/test_staking_lifecycle.py index 92219cad..18d3a723 100644 --- a/tests/integration/test_staking_lifecycle.py +++ b/tests/integration/test_staking_lifecycle.py @@ -3,13 +3,16 @@ Staking Lifecycle Integration Tests Test 3.1.1: Complete staking lifecycle integration test """ -import pytest import asyncio import sys +from pathlib import Path from datetime import datetime, timedelta -sys.path.insert(0, "/opt/aitbc/apps/coordinator-api/src") -sys.path.insert(0, "/opt/aitbc/contracts") +import pytest + +repo_root = Path(__file__).resolve().parents[2] +sys.path.insert(0, str(repo_root / "apps/coordinator-api/src")) +sys.path.insert(0, str(repo_root / "contracts")) # Import after path setup from sqlalchemy import create_engine diff --git a/tests/services/test_staking_service.py b/tests/services/test_staking_service.py index 1b253b87..d1d32c6e 100644 --- a/tests/services/test_staking_service.py +++ b/tests/services/test_staking_service.py @@ -3,15 +3,16 @@ Staking Service Tests High-priority tests for staking service functionality """ -import pytest import asyncio import sys +from pathlib import Path from datetime import datetime, timedelta + +import pytest from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker, Session -import sys -sys.path.insert(0, "/opt/aitbc/apps/coordinator-api/src") +sys.path.insert(0, str(Path(__file__).resolve().parents[2] / "apps/coordinator-api/src")) from app.domain.bounty import AgentStake, AgentMetrics, StakingPool, StakeStatus, PerformanceTier from app.services.staking_service import StakingService