Python: improve .env handling and observability samples (#4032)

* Python: improve .env precedence and observability samples

- Switch load_settings to explicit precedence: overrides -> explicit .env -> environment -> defaults\n- Raise when env_file_path is provided but missing\n- Update settings docs and tests for new behavior\n- Refresh observability samples and README guidance for env loading options\n\nCloses #3864\n\nCo-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* fixed some imports

* Fix load_settings CI regressions

Allow explicit env_file_path values that exist but are not regular files (for example /dev/null) by checking path existence before dotenv parsing, and restore a dict accumulator with typed return cast to satisfy mypy.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Avoid implicit dotenv in observability

Only load dotenv in observability helpers when env_file_path is explicitly provided, and remove test os.devnull workarounds that are no longer necessary.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Eduard van Valkenburg
2026-02-18 12:18:52 +01:00
committed by GitHub
Unverified
parent f900febb6f
commit 534e5f5bf7
41 changed files with 250 additions and 221 deletions
@@ -7,16 +7,6 @@ from typing import Any
import pytest
from pytest import MonkeyPatch, mark, param
from samples.getting_started.agents.azure_ai.azure_ai_with_function_tools import (
mixed_tools_example as azure_ai_with_function_tools_mixed,
)
from samples.getting_started.agents.azure_ai.azure_ai_with_function_tools import (
tools_on_agent_level as azure_ai_with_function_tools_agent,
)
from samples.getting_started.agents.azure_ai.azure_ai_with_function_tools import (
tools_on_run_level as azure_ai_with_function_tools_run,
)
from samples.getting_started.agents.azure_ai.azure_ai_basic import (
main as azure_ai_basic,
)
@@ -29,6 +19,15 @@ from samples.getting_started.agents.azure_ai.azure_ai_with_existing_agent import
from samples.getting_started.agents.azure_ai.azure_ai_with_explicit_settings import (
main as azure_ai_with_explicit_settings,
)
from samples.getting_started.agents.azure_ai.azure_ai_with_function_tools import (
mixed_tools_example as azure_ai_with_function_tools_mixed,
)
from samples.getting_started.agents.azure_ai.azure_ai_with_function_tools import (
tools_on_agent_level as azure_ai_with_function_tools_agent,
)
from samples.getting_started.agents.azure_ai.azure_ai_with_function_tools import (
tools_on_run_level as azure_ai_with_function_tools_run,
)
from samples.getting_started.agents.azure_ai.azure_ai_with_local_mcp import (
main as azure_ai_with_local_mcp,
)
@@ -7,7 +7,6 @@ from typing import Any
import pytest
from pytest import MonkeyPatch, mark, param
from samples.getting_started.client.azure_ai_chat_client import (
main as azure_ai_chat_client,
)
@@ -7,7 +7,6 @@ from typing import Any
import pytest
from pytest import MonkeyPatch, mark, param
from samples.getting_started.threads.custom_chat_message_store_thread import main as threads_custom_store
from samples.getting_started.threads.suspend_resume_thread import main as threads_suspend_resume