1313Or skip with: pytest -m "not e2e"
1414"""
1515
16+ import os
17+ import sys
1618import pytest
1719import asyncio
1820from datetime import datetime
2729load_dotenv ()
2830
2931
32+ def _build_server_params ():
33+ """Construct MCP server parameters using the active Python interpreter."""
34+ env = os .environ .copy ()
35+ repo_root = Path (__file__ ).resolve ().parents [2 ]
36+ src_path = repo_root / "src"
37+ if str (src_path ) not in env .get ("PYTHONPATH" , "" ):
38+ env ["PYTHONPATH" ] = os .pathsep .join (
39+ filter (None , [str (src_path ), env .get ("PYTHONPATH" , "" )])
40+ )
41+ return StdioServerParameters (
42+ command = sys .executable ,
43+ args = ["-m" , "garmin_mcp" ],
44+ env = env ,
45+ )
46+
47+
3048@pytest .mark .e2e
3149@pytest .mark .asyncio
3250@pytest .mark .timeout (30 ) # Pytest timeout
@@ -39,11 +57,7 @@ async def test_mcp_server_connection():
3957 - May require MFA code input if tokens are expired
4058 """
4159 # Use python module execution instead of direct script path
42- server_params = StdioServerParameters (
43- command = "python" ,
44- args = ["-m" , "garmin_mcp" ],
45- env = None , # Uses current environment which includes .env variables
46- )
60+ server_params = _build_server_params ()
4761
4862 # Connect to server with timeout
4963 try :
@@ -77,11 +91,7 @@ async def test_mcp_server_connection():
7791@pytest .mark .timeout (30 )
7892async def test_list_activities_tool ():
7993 """Test the list_activities MCP tool with real API"""
80- server_params = StdioServerParameters (
81- command = "python" ,
82- args = ["-m" , "garmin_mcp" ],
83- env = None ,
84- )
94+ server_params = _build_server_params ()
8595
8696 try :
8797 async with asyncio .timeout (20 ):
@@ -111,11 +121,7 @@ async def test_list_activities_tool():
111121@pytest .mark .timeout (30 )
112122async def test_get_steps_data_tool ():
113123 """Test the get_steps_data MCP tool with real API"""
114- server_params = StdioServerParameters (
115- command = "python" ,
116- args = ["-m" , "garmin_mcp" ],
117- env = None ,
118- )
124+ server_params = _build_server_params ()
119125
120126 try :
121127 async with asyncio .timeout (20 ):
@@ -147,11 +153,7 @@ async def test_get_steps_data_tool():
147153@pytest .mark .timeout (45 )
148154async def test_multiple_tools ():
149155 """Test multiple MCP tools in a single session"""
150- server_params = StdioServerParameters (
151- command = "python" ,
152- args = ["-m" , "garmin_mcp" ],
153- env = None ,
154- )
156+ server_params = _build_server_params ()
155157
156158 try :
157159 async with asyncio .timeout (40 ):
@@ -202,11 +204,7 @@ async def test_schedule_workouts_tool():
202204 import os
203205 import json
204206
205- server_params = StdioServerParameters (
206- command = "python" ,
207- args = ["-m" , "garmin_mcp" ],
208- env = None ,
209- )
207+ server_params = _build_server_params ()
210208
211209 workout_ids_env = os .environ .get ("GARMIN_TEST_WORKOUT_IDS" , "" )
212210 dates_env = os .environ .get ("GARMIN_TEST_SCHEDULE_DATES" , "" )
@@ -265,11 +263,7 @@ async def test_upload_workouts_tool():
265263 """
266264 import json
267265
268- server_params = StdioServerParameters (
269- command = "python" ,
270- args = ["-m" , "garmin_mcp" ],
271- env = None ,
272- )
266+ server_params = _build_server_params ()
273267
274268 minimal_workout = {
275269 "workoutName" : "e2e Test Workout - DELETE ME" ,
@@ -343,11 +337,7 @@ async def test_delete_workouts_tool():
343337 """
344338 import json
345339
346- server_params = StdioServerParameters (
347- command = "python" ,
348- args = ["-m" , "garmin_mcp" ],
349- env = None ,
350- )
340+ server_params = _build_server_params ()
351341
352342 try :
353343 async with asyncio .timeout (50 ):
@@ -393,11 +383,7 @@ async def test_schedule_workouts_inline_upload():
393383 """
394384 import json
395385
396- server_params = StdioServerParameters (
397- command = "python" ,
398- args = ["-m" , "garmin_mcp" ],
399- env = None ,
400- )
386+ server_params = _build_server_params ()
401387
402388 inline_workout = {
403389 "workoutName" : "e2e Inline Test - DELETE ME" ,
@@ -471,11 +457,7 @@ async def test_schedule_workouts_missing_required_fields():
471457 """
472458 import json
473459
474- server_params = StdioServerParameters (
475- command = "python" ,
476- args = ["-m" , "garmin_mcp" ],
477- env = None ,
478- )
460+ server_params = _build_server_params ()
479461
480462 try :
481463 async with asyncio .timeout (50 ):
0 commit comments