Skip to content

Commit 47f2d64

Browse files
use optional env for azure openai tests (#34517)
* use optional env for azure openai tests and remove v0 tests * update param ToxTestEnv in live test template * enable optional * debug * fix config options * fixes to path for audio file and install aiohttp dev req * remove debug logging line * debugging test failure * more debug * undo debug testing, use pathlib for paths, target sys.executable for cli tests * cspell ignores * no logprobs
1 parent a9e3bb0 commit 47f2d64

37 files changed

+69
-3368
lines changed

.vscode/cspell.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,6 +1273,19 @@
12731273
"genai"
12741274
]
12751275
},
1276+
{
1277+
"filename": "sdk/openai/azure-openai/**",
1278+
"words": [
1279+
"azuread",
1280+
"AZUREAD",
1281+
"dall",
1282+
"Lepardus",
1283+
"WEBVTT",
1284+
"logit",
1285+
"byod",
1286+
"logprobs"
1287+
]
1288+
},
12761289
{
12771290
"filename": "sdk/attestation/azure-security-attestation/tests/conftest.py",
12781291
"words":[

eng/pipelines/templates/jobs/live.tests.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ parameters:
5858
- name: TestProxy
5959
type: boolean
6060
default: false
61+
- name: ToxTestEnv
62+
type: string
63+
default: 'whl'
6164

6265
jobs:
6366
- job:
@@ -131,7 +134,7 @@ jobs:
131134
PostSteps: ${{ parameters.PostSteps }}
132135
PythonVersion: $(PythonVersion)
133136
OSVmImage: $(OSVmImage)
134-
ToxTestEnv: "whl"
137+
ToxTestEnv: ${{ parameters.ToxTestEnv }}
135138
AdditionalTestArgs: ${{ parameters.AdditionalTestArgs }}
136139
TestMarkArgument: ${{ parameters.TestMarkArgument }}
137140
InjectedPackages: ${{ parameters.InjectedPackages }}

eng/pipelines/templates/stages/archetype-sdk-tests.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ parameters:
9292
- name: TestProxy
9393
type: boolean
9494
default: false
95+
- name: ToxTestEnv
96+
type: string
97+
default: 'whl'
9598

9699
stages:
97100
- ${{ each cloud in parameters.CloudConfig }}:
@@ -126,6 +129,7 @@ stages:
126129
BuildDocs: ${{ parameters.BuildDocs }}
127130
TestTimeoutInMinutes: ${{ parameters.TestTimeoutInMinutes }}
128131
TestProxy: ${{ parameters.TestProxy }}
132+
ToxTestEnv: ${{ parameters.ToxTestEnv }}
129133
MatrixConfigs:
130134
# Enumerate platforms and additional platforms based on supported clouds (sparse platform<-->cloud matrix).
131135
- ${{ each config in parameters.MatrixConfigs }}:
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
-e ../../../tools/azure-sdk-tools
22
-e ../../../tools/azure-devtools
33
../../identity/azure-identity
4-
numpy
5-
aiohttp
6-
requests
74
httpx
5+
aiohttp

sdk/openai/azure-openai/pyproject.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,11 @@ mypy = false
44
pyright = false
55
type_check_samples = false
66
verifytypes = false
7+
8+
[[tool.azure-sdk-build.optional]]
9+
name = "main"
10+
install = ["git+https://github.com/openai/openai-python@main"]
11+
12+
[[tool.azure-sdk-build.optional]]
13+
name = "released"
14+
install = ["openai"]

sdk/openai/azure-openai/tests/conftest.py

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
import pytest
1010
import importlib
1111
import contextlib
12-
import requests
13-
import aiohttp
14-
import yarl
1512
import functools
1613
import openai
1714
from devtools_testutils.sanitizers import add_header_regex_sanitizer, add_oauth_response_sanitizer
@@ -21,8 +18,6 @@
2118
get_bearer_token_provider as get_bearer_token_provider_async,
2219
)
2320

24-
# controls whether we run tests against v0 or v1. Options: v0 or v1. Default: v1
25-
ENV_OPENAI_TEST_MODE = "OPENAI_TEST_MODE"
2621

2722
# for pytest.parametrize
2823
AZURE = "azure"
@@ -128,12 +123,9 @@ def azure_openai_creds():
128123
"chat_completion_gpt4_model": ENV_OPENAI_CHAT_COMPLETIONS_GPT4_MODEL,
129124
}
130125

131-
# openai>=1.0.0 ---------------------------------------------------------------------------
132126

133127
@pytest.fixture
134128
def client(api_type):
135-
if os.getenv(ENV_OPENAI_TEST_MODE, "v1") != "v1":
136-
pytest.skip("Skipping - tests set to run against v1.")
137129
if api_type == "azure":
138130
client = openai.AzureOpenAI(
139131
azure_endpoint=os.getenv(ENV_AZURE_OPENAI_ENDPOINT),
@@ -179,8 +171,6 @@ def client(api_type):
179171

180172
@pytest.fixture
181173
def client_async(api_type):
182-
if os.getenv(ENV_OPENAI_TEST_MODE, "v1") != "v1":
183-
pytest.skip("Skipping - tests set to run against v1.")
184174
if api_type == "azure":
185175
client = openai.AsyncAzureOpenAI(
186176
azure_endpoint=os.getenv(ENV_AZURE_OPENAI_ENDPOINT),
@@ -308,70 +298,3 @@ def reload():
308298
yield
309299
finally:
310300
importlib.reload(openai)
311-
312-
313-
# openai<1.0.0 ---------------------------------------------------------------------------
314-
315-
@pytest.fixture
316-
def set_vars(api_type):
317-
if os.getenv(ENV_OPENAI_TEST_MODE, "v1") != "v0":
318-
pytest.skip("Skipping - tests set to run against v0.")
319-
320-
if api_type == "azure":
321-
openai.api_base = os.getenv(ENV_AZURE_OPENAI_ENDPOINT).rstrip("/")
322-
openai.api_key = os.getenv(ENV_AZURE_OPENAI_KEY)
323-
openai.api_type = "azure"
324-
openai.api_version = ENV_AZURE_OPENAI_API_VERSION
325-
elif api_type == "azuread":
326-
openai.api_base = os.getenv(ENV_AZURE_OPENAI_ENDPOINT).rstrip("/")
327-
credential = DefaultAzureCredential()
328-
token = credential.get_token("https://cognitiveservices.azure.com/.default")
329-
openai.api_type = "azuread"
330-
openai.api_key = token.token
331-
openai.api_version = ENV_AZURE_OPENAI_API_VERSION
332-
elif api_type == "openai":
333-
openai.api_base = "https://api.openai.com/v1"
334-
openai.api_type = "openai"
335-
openai.api_key = os.getenv(ENV_OPENAI_KEY)
336-
openai.api_version = None
337-
elif api_type == "whisper_azure":
338-
openai.api_base = os.getenv(ENV_AZURE_OPENAI_NORTHCENTRALUS_ENDPOINT).rstrip("/")
339-
openai.api_key = os.getenv(ENV_AZURE_OPENAI_NORTHCENTRALUS_KEY)
340-
openai.api_type = "azure"
341-
openai.api_version = ENV_AZURE_OPENAI_API_VERSION
342-
elif api_type == "whisper_azuread":
343-
openai.api_base = os.getenv(ENV_AZURE_OPENAI_NORTHCENTRALUS_ENDPOINT).rstrip("/")
344-
credential = DefaultAzureCredential()
345-
token = credential.get_token("https://cognitiveservices.azure.com/.default")
346-
openai.api_type = "azuread"
347-
openai.api_key = token.token
348-
openai.api_version = ENV_AZURE_OPENAI_API_VERSION
349-
350-
351-
def configure_v0_async(f):
352-
@functools.wraps(f)
353-
async def wrapper(*args, **kwargs):
354-
api_type = kwargs.pop("api_type")
355-
set_vars = kwargs.pop("set_vars")
356-
azure_openai_creds = kwargs.pop("azure_openai_creds")
357-
try:
358-
return await f(*args, set_vars=set_vars, azure_openai_creds=azure_openai_creds, api_type=api_type, **kwargs)
359-
except openai.error.RateLimitError:
360-
pytest.skip(f"{str(f).split(' ')[1]}[{api_type}]: Skipping - Rate limit reached.")
361-
362-
return wrapper
363-
364-
365-
def configure_v0(f):
366-
@functools.wraps(f)
367-
def wrapper(*args, **kwargs):
368-
api_type = kwargs.pop("api_type")
369-
set_vars = kwargs.pop("set_vars")
370-
azure_openai_creds = kwargs.pop("azure_openai_creds")
371-
try:
372-
return f(*args, set_vars=set_vars, azure_openai_creds=azure_openai_creds, api_type=api_type, **kwargs)
373-
except openai.error.RateLimitError:
374-
pytest.skip(f"{str(f).split(' ')[1]}[{api_type}]: Skipping - Rate limit reached.")
375-
376-
return wrapper
377-
File renamed without changes.
File renamed without changes.

sdk/openai/azure-openai/tests/v1_tests/test_audio.py renamed to sdk/openai/azure-openai/tests/test_audio.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
from devtools_testutils import AzureRecordedTestCase
1111
from conftest import WHISPER_AZURE, OPENAI, WHISPER_ALL, configure, TTS_OPENAI, TTS_AZURE, TTS_AZURE_AD
1212

13-
audio_test_file = os.path.abspath(os.path.join(os.path.abspath(__file__), "..", "..", "./assets/hello.m4a"))
14-
audio_long_test_file = os.path.abspath(os.path.join(os.path.abspath(__file__), "..", "..", "./assets/wikipediaOcelot.wav"))
13+
audio_test_file = pathlib.Path(__file__).parent / "./assets/hello.m4a"
14+
audio_long_test_file = pathlib.Path(__file__).parent / "./assets/wikipediaOcelot.wav"
1515

1616
class TestAudio(AzureRecordedTestCase):
1717

sdk/openai/azure-openai/tests/v1_tests/test_audio_async.py renamed to sdk/openai/azure-openai/tests/test_audio_async.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
from devtools_testutils import AzureRecordedTestCase
1111
from conftest import WHISPER_AZURE, OPENAI, WHISPER_ALL, configure_async, TTS_OPENAI, TTS_AZURE, TTS_AZURE_AD
1212

13-
audio_test_file = os.path.abspath(os.path.join(os.path.abspath(__file__), "..", "..", "./assets/hello.m4a"))
14-
audio_long_test_file = os.path.abspath(os.path.join(os.path.abspath(__file__), "..", "..", "./assets/wikipediaOcelot.wav"))
13+
audio_test_file = pathlib.Path(__file__).parent / "./assets/hello.m4a"
14+
audio_long_test_file = pathlib.Path(__file__).parent / "./assets/wikipediaOcelot.wav"
1515

1616

1717
class TestAudioAsync(AzureRecordedTestCase):

0 commit comments

Comments
 (0)