Skip to content

Commit f4f57d7

Browse files
committed
Resolved comments
1 parent 20deee8 commit f4f57d7

File tree

4 files changed

+32
-47
lines changed

4 files changed

+32
-47
lines changed

sdk/ai/azure-ai-projects/.env.template

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -41,41 +41,18 @@ SHAREPOINT_PROJECT_CONNECTION_ID=
4141
A2A_PROJECT_CONNECTION_ID=
4242
BROWSER_AUTOMATION_PROJECT_CONNECTION_ID=
4343
OPENAPI_PROJECT_CONNECTION_ID=
44+
AI_SEARCH_USER_INPUT=
45+
SHAREPOINT_USER_INPUT=
46+
4447

4548
#######################################################################
4649
#
4750
# Used in tests
51+
#######################################################################
4852

49-
# Default Foundry endpoint for tests (specific test groups may read other variables below)
50-
AZURE_AI_PROJECTS_TESTS_PROJECT_ENDPOINT=
51-
52-
# Used in Agent tests
53-
AZURE_AI_PROJECTS_TESTS_AGENTS_PROJECT_ENDPOINT=
54-
AZURE_AI_PROJECTS_TESTS_MODEL_DEPLOYMENT_NAME=
55-
56-
# Used in tracing tests
57-
AZURE_AI_PROJECTS_TESTS_TRACING_PROJECT_ENDPOINT=
58-
59-
# Used in Container App Agents tests
60-
AZURE_AI_PROJECTS_TESTS_CONTAINER_PROJECT_ENDPOINT=
61-
AZURE_AI_PROJECTS_TESTS_CONTAINER_APP_RESOURCE_ID=
62-
AZURE_AI_PROJECTS_TESTS_CONTAINER_INGRESS_SUBDOMAIN_SUFFIX=
63-
64-
# Used in Agent Image Generation tests
65-
AZURE_AI_PROJECTS_TESTS_IMAGE_GENERATION_MODEL_DEPLOYMENT_NAME=
66-
67-
# Used in Memory Store tests
68-
AZURE_AI_PROJECTS_TESTS_MEMORY_STORE_CHAT_MODEL_DEPLOYMENT_NAME=
69-
AZURE_AI_PROJECTS_TESTS_MEMORY_STORE_EMBEDDING_MODEL_DEPLOYMENT_NAME=
70-
71-
# Connection IDs and settings used in agent tool tests
72-
AZURE_AI_PROJECTS_TESTS_BING_PROJECT_CONNECTION_ID=
73-
AZURE_AI_PROJECTS_TESTS_AI_SEARCH_PROJECT_CONNECTION_ID=
74-
AZURE_AI_PROJECTS_TESTS_AI_SEARCH_INDEX_NAME=
75-
AZURE_AI_PROJECTS_TESTS_AI_SEARCH_USER_INPUT=
76-
AZURE_AI_PROJECTS_TESTS_MCP_PROJECT_CONNECTION_ID=
77-
AZURE_AI_PROJECTS_TESTS_SHAREPOINT_PROJECT_CONNECTION_ID=
78-
AZURE_AI_PROJECTS_TESTS_SHAREPOINT_USER_INPUT=
53+
# Used for recording or playback
54+
AZURE_TEST_RUN_LIVE=false
55+
AZURE_SKIP_LIVE_RECORDING=true
7956

8057
# Used in Fine-tuning tests
8158
AZURE_AI_PROJECTS_TESTS_COMPLETED_OAI_MODEL_SFT_FINE_TUNING_JOB_ID=

sdk/ai/azure-ai-projects/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

sdk/ai/azure-ai-projects/tests/conftest.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@
2222
add_body_regex_sanitizer,
2323
)
2424

25-
if not load_dotenv(find_dotenv(filename=".test.env"), override=True):
26-
print("Failed to apply environment variables for azure-ai-projects tests.")
27-
25+
if not load_dotenv(find_dotenv(), override=True):
26+
print("Did not find a .env file. Using default environment variable values for tests.")
2827

2928
def pytest_collection_modifyitems(items):
3029
if os.environ.get("AZURE_TEST_RUN_LIVE") == "true":

sdk/ai/azure-ai-projects/tests/samples/README.md

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
## Recorded sample tests
1+
# Recorded sample tests
22

33
Use recorded tests to validate samples with `SyncSampleExecutor` and `AsyncSampleExecutor`. Tests run the sample code, fail on exceptions, and can optionally validate captured `print` output through LLM instructions.
44

5-
### Prerequisites
5+
## Prerequisites
6+
67
- In `.env`, set the variables required by your samples plus `AZURE_TEST_RUN_LIVE=true` and `AZURE_SKIP_LIVE_RECORDING=false` when capturing recordings. CI playback typically uses `AZURE_TEST_RUN_LIVE=false` and `AZURE_SKIP_LIVE_RECORDING=true`.
78
- Provide sanitized defaults via `servicePreparer` so recordings do not leak secrets. All mandatory environment variables used by the tests/samples must be specified in `servicePreparer` (as sanitized values) so playback can run without access to real secrets.
89

910
**VS Code tip (record a single sample):** Open the **Testing** tab, expand the pytest tree to find the specific sample test case (for example, one parameterized case for a particular `sample_path`), then right-click it and choose **Run Test** (or **Debug Test**). Make sure your `.env` (or your test run environment) includes `AZURE_TEST_RUN_LIVE=true` and `AZURE_SKIP_LIVE_RECORDING=false` so that run captures a new recording for just that sample.
1011

11-
### Sync example
12+
## Sync example
13+
1214
```python
1315
import pytest
1416
import os
@@ -49,7 +51,8 @@ class TestSamples(AzureRecordedTestCase):
4951
)
5052
```
5153

52-
### Async example
54+
## Async example
55+
5356
```python
5457
import pytest
5558
from devtools_testutils.aio import recorded_by_proxy_async
@@ -86,9 +89,11 @@ class TestSamplesAsync(AzureRecordedTestCase):
8689
)
8790
```
8891

89-
### Key pieces
92+
## Key pieces
93+
9094
- `@servicePreparer()`: A custom helper you create for your test suite. It supplies sanitized environment variables for playback (often via `EnvironmentVariableLoader`). The name is up to you; these examples call it `servicePreparer` by convention.
9195
- Example:
96+
9297
```python
9398
import functools
9499
from devtools_testutils import EnvironmentVariableLoader
@@ -101,8 +106,10 @@ servicePreparer = functools.partial(
101106
# add other sanitized vars here
102107
)
103108
```
109+
104110
- If all your test environment variables share a prefix (for example `azure_ai_projects_tests`), pass that prefix as the second positional
105111
argument to `EnvironmentVariableLoader` and include the prefix on the keys you provide. For example:
112+
106113
```python
107114
servicePreparer = functools.partial(
108115
EnvironmentVariableLoader,
@@ -112,14 +119,16 @@ servicePreparer = functools.partial(
112119
# add other sanitized vars here
113120
)
114121
```
122+
115123
- `@pytest.mark.parametrize`: Drives one test per sample file. Use `samples_to_test` or `samples_to_skip` with `get_sample_paths` / `get_async_sample_paths`.
116124
- `@SamplePathPasser`: Forwards the sample path to the recorder decorators.
117125
- `recorded_by_proxy` / `recorded_by_proxy_async`: Wrap tests for recording/playback. Include `RecordedTransport.HTTPX` when samples use httpx in addition to the default `RecordedTransport.AZURE_CORE`.
118126
- `execute` / `execute_async`: Run the sample; any exception fails the test.
119127
- `validate_print_calls_by_llm` / `validate_print_calls_by_llm_async`: Optionally validate captured print output with LLM instructions and an explicit `project_endpoint` (and optional `model`).
120128
- `kwargs` in the test function: A dictionary with environment variables in key and value pairs.
121129

122-
### Optional test environment variables mapping
130+
## Optional test environment variables mapping
131+
123132
If you need to remap the environment variable names provided by your fixtures to the names the sample expects, pass a dictionary via the `env_var_mapping` kwarg on the sample executors. When your fixtures already supply the sample-ready names, you can omit `env_var_mapping`.
124133

125134
```python
@@ -130,7 +139,8 @@ env_var_mapping = {
130139
executor = SyncSampleExecutor(self, sample_path, env_var_mapping=env_var_mapping, **kwargs)
131140
```
132141

133-
### Optional environment variables
142+
## Optional environment variables
143+
134144
To run the “hero path” of a sample, your `@servicePreparer` should provide all mandatory environment variables.
135145
If a sample supports optional environment variables (for optional features/paths), use `@additionalSampleTests` to generate additional recorded test cases with those optional variables set.
136146

@@ -169,12 +179,12 @@ def test_agent_tools_samples(self, sample_path: str, **kwargs) -> None:
169179
```
170180

171181
Notes:
182+
172183
- `AdditionalSampleTestDetail.env_vars` is a mapping of **sample env-var name** -> **sanitized playback value**.
173-
- Live/recording (`AZURE_TEST_RUN_LIVE=true`): reads the real value from your environment (for example, from `.env`) and sanitizes it to the provided playback value.
174-
- Playback (`AZURE_TEST_RUN_LIVE=false`): sets each key to the provided playback value.
184+
- Live/recording (`AZURE_TEST_RUN_LIVE=true`): reads the real value from your environment (for example, from `.env`) and sanitizes it to the provided playback value.
185+
- Playback (`AZURE_TEST_RUN_LIVE=false`): sets each key to the provided playback value.
175186
- `AdditionalSampleTestDetail.test_id` customizes the parameter id used for that variant.
176-
- If omitted, the id is auto-generated from the sample filename and env-var keys (for example, `sample_agent_computer_use-[COMPUTER_USE_MODEL_DEPLOYMENT_NAME]`).
177-
- If provided, it becomes the full parameter id for that variant (no filename prefix).
178-
- If the auto-generated id makes the recording file path too long (most commonly on Windows), the recording file may fail to generate; set a short `test_id` (and keep it unique across all parametrized cases).
187+
- If omitted, the id is auto-generated from the sample filename and env-var keys (for example, `sample_agent_computer_use-[COMPUTER_USE_MODEL_DEPLOYMENT_NAME]`).
188+
- If provided, it becomes the full parameter id for that variant (no filename prefix).
189+
- If the auto-generated id makes the recording file path too long (most commonly on Windows), the recording file may fail to generate; set a short `test_id` (and keep it unique across all parametrized cases).
179190
- In VS Code’s **Testing** tab, these show up as additional parameterized cases for the same test, using the parameter id.
180-

0 commit comments

Comments
 (0)