Skip to content

Commit a23e32c

Browse files
More advanced pytesting
1 parent 01daf15 commit a23e32c

4 files changed

Lines changed: 33 additions & 28 deletions

File tree

.vscode/settings.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
"azureFunctions.projectRuntime": "~4",
88
"debug.internalConsoleOptions": "neverOpen",
99
"python.testing.pytestArgs": [
10-
"backend"
10+
"backend",
11+
"-v"
1112
],
1213
"python.testing.unittestEnabled": false,
13-
"python.testing.pytestEnabled": true
14+
"python.testing.pytestEnabled": true,
15+
"python-envs.pythonProjects": []
1416
}

backend/generate_quiz.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ class QuizGenerator:
2727
"gpt-4-turbo",
2828
"o1-mini",
2929
"o3-mini",
30+
"azure_ai/gpt-35-turbo", # Azure AI GPT-3.5-turbo
31+
"azure_ai/gpt-4-turbo", # Azure AI GPT-4-turbo
32+
"azure_ai/gpt-4o", # Azure AI GPT-4o
33+
"azure_ai/gpt-4o-mini", # Azure AI GPT-4o-mini
34+
"azure_ai/o1-mini", # Azure AI O1-mini
35+
"azure_ai/o1-preview", # Azure AI O1-preview
36+
"azure_ai/o3-mini", # Azure AI O3-mini
3037
"gemini/gemini-2.0-flash",
3138
"gemini/gemini-1.5-pro-latest",
3239
"azure_ai/DeepSeek-R1",
@@ -212,15 +219,7 @@ def print_quiz(generator: Generator[str, None, None]):
212219
# For detailed output during testing, set the logger level to DEBUG.
213220
logger.setLevel(logging.DEBUG)
214221

215-
suppported_models = [
216-
"gpt-3.5-turbo",
217-
"gpt-4-turbo",
218-
"o1-mini",
219-
"o3-mini",
220-
"gemini/gemini-pro",
221-
"gemini/gemini-1.5-pro-latest",
222-
"azure_ai/DeepSeek-R1",
223-
]
222+
print(f"Supported models: {QuizGenerator.SUPPORTED_MODELS}")
224223

225224
quiz_generator = QuizGenerator(model="o1-mini")
226225

backend/pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ select = ["E", "F", "W", "I"]
3535
markers = [
3636
"integration: mark test as an integration test."
3737
]
38-
addopts = "-m 'not integration'"
3938
testpaths = ["tests"]
4039

4140
[dependency-groups]

backend/tests/test_generate_quiz.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -104,23 +104,28 @@ class TestQuizGeneratorIntegration:
104104
"""
105105

106106
@pytest.mark.integration
107-
def test_generate_quiz_real_api(self):
108-
"""
109-
Integration test that calls the real OpenAI API.
110-
111-
This test will only run if the OPENAI_API_KEY is set in the environment. It verifies that the
112-
generate_quiz method returns at least one SSE-formatted result.
113-
"""
114-
api_key = os.getenv("OPENAI_API_KEY")
115-
if not api_key:
116-
pytest.skip("Skipping integration test: OPENAI_API_KEY not set.")
117-
quiz_gen = QuizGenerator()
118-
topic = "Math"
119-
difficulty = "Hard"
120-
gen = quiz_gen.generate_quiz(topic, difficulty, 2)
121-
# Collect the output from the generator.
107+
@pytest.mark.parametrize("model", QuizGenerator.SUPPORTED_MODELS)
108+
def test_model(self, model):
109+
"""Test each supported model individually."""
110+
# Check if required API keys are available
111+
provider = model.split("/")[0]
112+
113+
if provider == "openai" and not os.getenv("OPENAI_API_KEY"):
114+
pytest.skip("OPENAI_API_KEY not set")
115+
elif provider == "gemini" and not os.getenv("GEMINI_API_KEY"):
116+
pytest.skip("GEMINI_API_KEY not set")
117+
elif provider == "deepseek" and not os.getenv("DEEPSEEK_API_KEY"):
118+
pytest.skip("DEEPSEEK_API_KEY not set")
119+
elif provider == "azure_ai" and (
120+
not os.getenv("AZURE_AI_API_KEY") or not os.getenv("AZURE_AI_API_BASE")
121+
):
122+
pytest.skip("Azure AI credentials not set")
123+
124+
# Test the model
125+
quiz_gen = QuizGenerator(model=model)
126+
gen = quiz_gen.generate_quiz("Math", "Easy", 1)
122127
results = list(gen)
123-
# Verify that at least one SSE event is produced.
128+
124129
assert len(results) > 0
125130
for r in results:
126131
assert r.startswith("data: ")

0 commit comments

Comments
 (0)