Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ python -m pytest tests/unit
### Integration Tests

Integration tests validate the **end-to-end behavior** of vCache by checking how components interact (e.g., LLM inference + vector database + thresholding policy).
They may involve real API calls and require a valid OpenAI key.
Tests that make real API calls require a valid OpenAI key. Pytest skips those tests when `OPENAI_API_KEY` is not set and still runs integration tests that do not require the API.

#### Running Integration Tests

Expand Down
41 changes: 41 additions & 0 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import os

import pytest

_REQUIRES_OPENAI_MARKER: str = "requires_openai"


def pytest_configure(config: pytest.Config) -> None:
"""Register the ``requires_openai`` marker.

Args:
config: The active pytest configuration object.
"""
config.addinivalue_line(
"markers",
f"{_REQUIRES_OPENAI_MARKER}: test needs a live OPENAI_API_KEY to run.",
)


def pytest_collection_modifyitems(
config: pytest.Config, items: list[pytest.Item]
) -> None:
"""Skip live OpenAI tests when no API key is available.

Pull requests opened from forks do not receive repository secrets, so
``OPENAI_API_KEY`` is empty in those CI runs. Tests that call the real
OpenAI API are skipped instead of failing with an empty ``Bearer`` header.

Args:
config: The active pytest configuration object.
items: The collected test items to inspect and mark for skipping.
"""
if os.environ.get("OPENAI_API_KEY"):
return

skip_marker: pytest.MarkDecorator = pytest.mark.skip(
reason="OPENAI_API_KEY not set; skipping live OpenAI integration test."
)
for item in items:
if item.get_closest_marker(_REQUIRES_OPENAI_MARKER) is not None:
item.add_marker(skip_marker)
3 changes: 3 additions & 0 deletions tests/integration/test_dynamic_threshold.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import unittest

import pytest
from dotenv import load_dotenv

from vcache import (
Expand All @@ -14,6 +15,8 @@

load_dotenv()

pytestmark = pytest.mark.requires_openai


def create_default_config_and_policy():
config = VCacheConfig(
Expand Down
3 changes: 3 additions & 0 deletions tests/integration/test_no_cache.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import unittest
from unittest.mock import MagicMock

import pytest
from dotenv import load_dotenv

from vcache import (
Expand All @@ -12,6 +13,8 @@

load_dotenv()

pytestmark = pytest.mark.requires_openai


def create_default_config_and_policy():
config = VCacheConfig(
Expand Down
3 changes: 3 additions & 0 deletions tests/integration/test_static_threshold.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import unittest

import pytest
from dotenv import load_dotenv

from vcache import (
Expand All @@ -14,6 +15,8 @@

load_dotenv()

pytestmark = pytest.mark.requires_openai


def create_default_config_and_policy():
config = VCacheConfig(
Expand Down
Loading