Skip to content

Commit 95b9622

Browse files
qchappCopilot
andauthored
Potential fix for pull request finding
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 09d0474 commit 95b9622

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

tests/test_gpt4o_vision.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,19 @@
1111

1212
load_dotenv()
1313

14+
# Track missing dependencies so we don't call sys.exit at import time.
15+
MISSING_OPENAI_API_KEY = False
16+
MISSING_PILLOW = False
17+
1418
# Check environment
1519
openai_key = os.getenv("OPENAI_API_KEY")
1620
if not openai_key:
1721
print("❌ OPENAI_API_KEY not found in environment")
1822
print(" Set it in .env or export OPENAI_API_KEY=your_key")
19-
sys.exit(1)
20-
21-
print("✅ OPENAI_API_KEY found")
22-
print()
23+
MISSING_OPENAI_API_KEY = True
24+
else:
25+
print("✅ OPENAI_API_KEY found")
26+
print()
2327

2428
# Import pydantic-ai components (matching agent.py pattern)
2529
from pydantic_ai import Agent
@@ -58,10 +62,15 @@ class VisionTestResponse(BaseModel):
5862
print(f"✅ Test image created: {test_image_path} ({len(PNG_1x1_RED)} bytes)")
5963
except ImportError:
6064
print("❌ PIL/Pillow not installed. Install with: pip install Pillow")
61-
sys.exit(1)
65+
MISSING_PILLOW = True
6266

6367
print()
6468

69+
if __name__ == "__main__":
70+
# When run as a script, exit with a non-zero status if required dependencies are missing.
71+
if MISSING_OPENAI_API_KEY or MISSING_PILLOW:
72+
sys.exit(1)
73+
6574
# Create OpenAI provider and model (matching agent.py)
6675
print("🔄 Creating OpenAI gpt-4o model client...")
6776
provider = OpenAIProvider(api_key=openai_key)

0 commit comments

Comments
 (0)