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
4 changes: 4 additions & 0 deletions .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ jobs:
run: |
poetry run mypy landingai
- name: Test with pytest
env:
# Not available to pull requests from forks; the integration tests that
# need it skip themselves when it is empty.
LANDINGAI_API_KEY: ${{ secrets.LANDINGAI_API_KEY }}
run: |
poetry run pytest -v tests

Expand Down
13 changes: 12 additions & 1 deletion tests/integration/landingai/test_predict_e2e.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import os
from pathlib import Path

import numpy as np
Expand All @@ -9,7 +10,17 @@
from landingai.predict import OcrPredictor, Predictor
from landingai.visualize import overlay_predictions

_API_KEY = "land_sk_aMemWbpd41yXnQ0tXvZMh59ISgRuKNRKjJEIUHnkiH32NBJAwf"
# These tests call live LandingLens endpoints, so they need a real API key.
# It is read from the LANDINGAI_API_KEY environment variable, which CI populates
# from the repository secret of the same name. Secrets are not exposed to
# workflow runs triggered by pull requests from forks, so skip instead of
# failing when the key is absent.
_API_KEY = os.environ.get("LANDINGAI_API_KEY", "")

pytestmark = pytest.mark.skipif(
not _API_KEY,
reason="LANDINGAI_API_KEY is not set; skipping tests that call live endpoints.",
)

_EXPECTED_VP_PREDS = [
{
Expand Down
26 changes: 26 additions & 0 deletions tests/unit/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import pytest

# Both cases are cleared because pydantic-settings matches env vars
# case-insensitively, and the tests below set the lowercase spelling.
_API_CREDENTIAL_ENV_VARS = (
"LANDINGAI_API_KEY",
"landingai_api_key",
"LANDINGAI_API_SECRET",
"landingai_api_secret",
)


@pytest.fixture(autouse=True)
def unset_api_credential_env_vars(monkeypatch):
"""Isolate unit tests from API credentials in the ambient environment.

CI exports LANDINGAI_API_KEY so the integration tests can call live
endpoints. Environment variables take precedence over .env files, so
without this the credential-loading tests would read the real key instead
of the one they set up, and the tests asserting that an invalid or missing
key raises would silently find a valid one.

Tests that need a credential set it themselves after this fixture runs.
"""
for var in _API_CREDENTIAL_ENV_VARS:
monkeypatch.delenv(var, raising=False)
Loading