@@ -30,8 +30,11 @@ def step_run_cli_command(context, command):
3030 test_env = os .environ .copy ()
3131 test_env ["FORCE_COLOR" ] = "1" # Force colored output
3232 test_env ["CLICOLOR_FORCE" ] = "1" # Force colored output
33- test_env ["TOWER_URL" ] = context .tower_url # Use mock API
34- test_env ["TOWER_JWT" ] = "mock_jwt_token"
33+ test_env ["TOWER_URL" ] = context .tower_url # Use configured API URL
34+
35+ # Only set mock JWT if not already configured externally
36+ if "TOWER_JWT" not in os .environ :
37+ test_env ["TOWER_JWT" ] = "mock_jwt_token"
3538
3639 # Override HOME to use test session
3740 test_home = Path (__file__ ).parent .parent .parent / "test-home"
@@ -45,9 +48,11 @@ def step_run_cli_command(context, command):
4548 env = test_env ,
4649 )
4750 context .cli_output = result .stdout + result .stderr
51+ context .cli_stdout = result .stdout
4852 context .cli_return_code = result .returncode
4953 except subprocess .TimeoutExpired :
5054 context .cli_output = "Command timed out"
55+ context .cli_stdout = ""
5156 context .cli_return_code = 124
5257 except Exception as e :
5358 print (f"DEBUG: Exception in CLI command: { type (e ).__name__ } : { e } " )
@@ -267,11 +272,17 @@ def step_table_should_show_columns(context, column_list):
267272 assert column in output , f"Expected column '{ column } ' in table, got: { output } "
268273
269274
275+ def parse_cli_json (context ):
276+ """Parse JSON from CLI stdout (excludes stderr)."""
277+ raw = getattr (context , "cli_stdout" , context .cli_output )
278+ return json .loads (raw )
279+
280+
270281@step ("the output should be valid JSON" )
271282def step_output_should_be_valid_json (context ):
272283 """Verify output is valid JSON"""
273284 try :
274- json . loads (context . cli_output )
285+ parse_cli_json (context )
275286 except json .JSONDecodeError as e :
276287 raise AssertionError (
277288 f"Output is not valid JSON: { e } \n Output: { context .cli_output } "
@@ -281,7 +292,7 @@ def step_output_should_be_valid_json(context):
281292@step ("the JSON should contain app information" )
282293def step_json_should_contain_app_info (context ):
283294 """Verify JSON contains app-related information"""
284- data = json . loads (context . cli_output )
295+ data = parse_cli_json (context )
285296 assert (
286297 "app" in data or "name" in data
287298 ), f"Expected app information in JSON, got: { data } "
@@ -290,7 +301,7 @@ def step_json_should_contain_app_info(context):
290301@step ("the JSON should contain runs array" )
291302def step_json_should_contain_runs_array (context ):
292303 """Verify JSON contains runs array"""
293- data = json . loads (context . cli_output )
304+ data = parse_cli_json (context )
294305 assert "runs" in data and isinstance (
295306 data ["runs" ], list
296307 ), f"Expected runs array in JSON, got: { data } "
@@ -299,7 +310,7 @@ def step_json_should_contain_runs_array(context):
299310@step ("the JSON should contain the created app information" )
300311def step_json_should_contain_created_app_info (context ):
301312 """Verify JSON contains created app information"""
302- data = json . loads (context . cli_output )
313+ data = parse_cli_json (context )
303314
304315 expected = IsPartialDict (
305316 result = "success" ,
@@ -319,7 +330,7 @@ def step_json_should_contain_created_app_info(context):
319330@step ('the app name should be "{expected_name}"' )
320331def step_app_name_should_be (context , expected_name ):
321332 """Verify app name matches expected value"""
322- data = json . loads (context . cli_output )
333+ data = parse_cli_json (context )
323334 # Extract app name from response structure
324335 if "app" in data and "name" in data ["app" ]:
325336 actual_name = data ["app" ]["name" ]
@@ -338,7 +349,7 @@ def step_app_name_should_be(context, expected_name):
338349@step ('the app description should be "{expected_description}"' )
339350def step_app_description_should_be (context , expected_description ):
340351 """Verify app description matches expected value"""
341- data = json . loads (context . cli_output )
352+ data = parse_cli_json (context )
342353 candidates = []
343354
344355 if "app" in data :
0 commit comments