Skip to content

Commit 3c3c325

Browse files
committed
remove redundant typing import and fix SIM115
1 parent 3a90be8 commit 3c3c325

File tree

3 files changed

+10
-48
lines changed

3 files changed

+10
-48
lines changed

python/packages/azurefunctions/agent_framework_azurefunctions/_serialization.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import logging
1212
import types
1313
from dataclasses import asdict, fields, is_dataclass
14-
from typing import Any, Union, get_args, get_origin
14+
from typing import Any, Union, get_args, get_origin, get_type_hints
1515

1616
from agent_framework import (
1717
AgentExecutorRequest,
@@ -169,9 +169,7 @@ def _reconstruct_dataclass_fields(dataclass_type: type, data: dict[str, Any]) ->
169169

170170
# Get type hints for the dataclass
171171
try:
172-
import typing
173-
174-
type_hints = typing.get_type_hints(dataclass_type)
172+
type_hints = get_type_hints(dataclass_type)
175173
except Exception:
176174
# Fall back to field annotations if get_type_hints fails
177175
for f in fields(dataclass_type):

python/packages/azurefunctions/tests/integration_tests/conftest.py

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
This module provides fixtures and configuration for pytest.
66
"""
77

8-
import logging
98
import subprocess
109
import sys
1110
from collections.abc import Iterator, Mapping
@@ -15,12 +14,10 @@
1514
import pytest
1615
import requests
1716

18-
logger = logging.getLogger(__name__)
19-
2017
# Add the integration_tests directory to the path so testutils can be imported
2118
sys.path.insert(0, str(Path(__file__).parent))
2219

23-
from testutils import ( # noqa: E402
20+
from testutils import (
2421
FunctionAppStartupError,
2522
build_base_url,
2623
cleanup_function_app,
@@ -93,34 +90,22 @@ class TestSample01SingleAgent:
9390
max_attempts = 3
9491
last_error: Exception | None = None
9592
func_process: subprocess.Popen[Any] | None = None
96-
log_file: Any = None
9793
base_url = ""
9894
port = 0
9995

10096
for _ in range(max_attempts):
10197
port = find_available_port()
10298
base_url = build_base_url(port)
103-
func_process, log_file = start_function_app(sample_path, port)
99+
func_process = start_function_app(sample_path, port)
104100

105101
try:
106102
wait_for_function_app_ready(func_process, port)
107103
last_error = None
108104
break
109105
except FunctionAppStartupError as exc:
110-
log_file.seek(0)
111-
logs = log_file.read().decode("utf-8", errors="replace")
112-
last_error = FunctionAppStartupError(f"{exc}\nLogs:\n{logs}")
106+
last_error = exc
113107
cleanup_function_app(func_process)
114-
log_file.close()
115108
func_process = None
116-
log_file = None
117-
except BaseException:
118-
# Capture logs on timeout or other interruptions
119-
if log_file:
120-
log_file.seek(0)
121-
logs = log_file.read().decode("utf-8", errors="replace")
122-
logger.info("[Startup Interrupted] Partial Logs:\n%s", logs)
123-
raise
124109

125110
if func_process is None:
126111
error_message = f"Function app failed to start after {max_attempts} attempt(s)."
@@ -133,12 +118,6 @@ class TestSample01SingleAgent:
133118
finally:
134119
if func_process is not None:
135120
cleanup_function_app(func_process)
136-
if log_file is not None:
137-
log_file.seek(0)
138-
logger.info("\n=== Function App Logs ===")
139-
logger.info(log_file.read().decode("utf-8", errors="replace"))
140-
logger.info("=========================")
141-
log_file.close()
142121

143122

144123
@pytest.fixture(scope="module")

python/packages/azurefunctions/tests/integration_tests/testutils.py

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import socket
1010
import subprocess
1111
import sys
12-
import tempfile
1312
import time
1413
import uuid
1514
from contextlib import suppress
@@ -295,44 +294,30 @@ def load_and_validate_env() -> None:
295294
)
296295

297296

298-
def start_function_app(sample_path: Path, port: int) -> tuple[subprocess.Popen, Any]:
297+
def start_function_app(sample_path: Path, port: int) -> subprocess.Popen:
299298
"""
300299
Start a function app in the specified sample directory.
301300
302-
Returns the subprocess.Popen object and the log file handle.
301+
Returns the subprocess.Popen object for the running process.
303302
"""
304303
env = os.environ.copy()
305304
# Use a unique TASKHUB_NAME for each test run to ensure test isolation.
306305
# This prevents conflicts between parallel or repeated test runs, as Durable Functions
307306
# use the task hub name to separate orchestration state.
308307
env["TASKHUB_NAME"] = f"test{uuid.uuid4().hex[:8]}"
309308

310-
# The log_file handle is returned to the caller and must remain open beyond this function,
311-
# so we intentionally do not use a context manager here. # noqa: SIM115
312-
log_file = tempfile.TemporaryFile()
313-
314309
# On Windows, use CREATE_NEW_PROCESS_GROUP to allow proper termination
315310
# shell=True only on Windows to handle PATH resolution
316311
if sys.platform == "win32":
317-
process = subprocess.Popen(
318-
["func", "start", "--verbose", "--port", str(port)],
312+
return subprocess.Popen(
313+
["func", "start", "--port", str(port)],
319314
cwd=str(sample_path),
320315
creationflags=subprocess.CREATE_NEW_PROCESS_GROUP,
321316
shell=True,
322317
env=env,
323-
stdout=log_file,
324-
stderr=subprocess.STDOUT,
325318
)
326-
return process, log_file
327319
# On Unix, don't use shell=True to avoid shell wrapper issues
328-
process = subprocess.Popen(
329-
["func", "start", "--verbose", "--port", str(port)],
330-
cwd=str(sample_path),
331-
env=env,
332-
stdout=log_file,
333-
stderr=subprocess.STDOUT,
334-
)
335-
return process, log_file
320+
return subprocess.Popen(["func", "start", "--port", str(port)], cwd=str(sample_path), env=env)
336321

337322

338323
def wait_for_function_app_ready(func_process: subprocess.Popen, port: int, max_wait: int = 60) -> None:

0 commit comments

Comments
 (0)