Skip to content

Commit 1c2a616

Browse files
abrookinsbsbodden
authored andcommitted
chore: Skip API-dependent tests in CI
1 parent 240e551 commit 1c2a616

File tree

7 files changed

+63
-21
lines changed

7 files changed

+63
-21
lines changed

.github/workflows/test.yml

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
2-
name: Lint
1+
name: Test Suite
32

43
on:
54
pull_request:
5+
66
push:
77
branches:
88
- main
@@ -11,37 +11,49 @@ env:
1111
POETRY_VERSION: "1.8.3"
1212

1313
jobs:
14-
check:
15-
name: Style-check ${{ matrix.python-version }}
14+
test:
15+
name: Python ${{ matrix.python-version }} - ${{ matrix.connection }} [redis-stack ${{matrix.redis-stack-version}}]
1616
runs-on: ubuntu-latest
17+
1718
strategy:
19+
fail-fast: false
1820
matrix:
19-
# Only lint on the min and max supported Python versions.
20-
# It's extremely unlikely that there's a lint issue on any version in between
21-
# that doesn't show up on the min or max versions.
22-
#
23-
# GitHub rate-limits how many jobs can be running at any one time.
24-
# Starting new jobs is also relatively slow,
25-
# so linting on fewer versions makes CI faster.
26-
python-version:
27-
- "3.9"
28-
- "3.10"
29-
- "3.11"
30-
- "3.12"
21+
python-version: [3.9, '3.10', 3.11, 3.12]
22+
connection: ['hiredis', 'plain']
23+
redis-stack-version: ['6.2.6-v9', 'latest', 'edge']
24+
25+
services:
26+
redis:
27+
image: redis/redis-stack-server:${{matrix.redis-stack-version}}
28+
ports:
29+
- 6379:6379
3130

3231
steps:
3332
- uses: actions/checkout@v2
3433
- name: Set up Python ${{ matrix.python-version }}
35-
uses: actions/setup-python@v2
34+
uses: actions/setup-python@v4
3635
with:
3736
python-version: ${{ matrix.python-version }}
37+
cache: 'pip'
38+
3839
- name: Install Poetry
3940
uses: snok/install-poetry@v1
4041
with:
4142
version: ${{ env.POETRY_VERSION }}
43+
4244
- name: Install dependencies
4345
run: |
4446
poetry install --all-extras
45-
- name: runt tests
47+
48+
- name: Install hiredis if needed
49+
if: matrix.connection == 'hiredis'
50+
run: |
51+
poetry add hiredis
52+
53+
- name: Set Redis version
54+
run: |
55+
echo "REDIS_VERSION=${{ matrix.redis-stack-version }}" >> $GITHUB_ENV
56+
57+
- name: Run tests
4658
run: |
47-
make test
59+
make ci_test

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
######################
66

77
test:
8-
poetry run pytest tests
8+
poetry run pytest tests --run-api-tests
99

1010
test_watch:
1111
poetry run ptw .
12+
13+
ci_test:
14+
poetry run pytest tests
1215

1316
######################
1417
# LINTING AND FORMATTING
@@ -32,4 +35,4 @@ lint lint_diff lint_package lint_tests:
3235

3336
format format_diff:
3437
poetry run ruff format $(PYTHON_FILES)
35-
poetry run ruff check --select I --fix $(PYTHON_FILES)
38+
poetry run ruff check --select I --fix $(PYTHON_FILES)

tests/conftest.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,26 @@ async def clear_redis(redis_url: str) -> None:
4848
client = Redis.from_url(redis_url)
4949
await client.flushall()
5050
await client.aclose() # type: ignore[attr-defined]
51+
52+
53+
def pytest_addoption(parser):
54+
parser.addoption(
55+
"--run-api-tests",
56+
action="store_true",
57+
default=False,
58+
help="Run tests that require API keys"
59+
)
60+
61+
def pytest_configure(config):
62+
config.addinivalue_line(
63+
"markers",
64+
"requires_api_keys: mark test as requiring API keys"
65+
)
66+
67+
def pytest_collection_modifyitems(config, items):
68+
if config.getoption("--run-api-tests"):
69+
return
70+
skip_api = pytest.mark.skip(reason="Skipping test because API keys are not provided. Use --run-api-tests to run these tests.")
71+
for item in items:
72+
if item.get_closest_marker("requires_api_keys"):
73+
item.add_marker(skip_api)

tests/test_async.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,7 @@ def model() -> ChatOpenAI:
539539
return ChatOpenAI(model="gpt-4-turbo-preview", temperature=0)
540540

541541

542+
@pytest.mark.requires_api_keys
542543
@pytest.mark.asyncio
543544
async def test_async_redis_checkpointer(
544545
redis_url: str, tools: List[BaseTool], model: ChatOpenAI

tests/test_async_store.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ async def test_large_batches(store: AsyncRedisStore) -> None:
480480
)
481481

482482

483+
@pytest.mark.requires_api_keys
483484
@pytest.mark.asyncio
484485
async def test_async_store_with_memory_persistence(
485486
redis_url: str,

tests/test_store.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@ def test_vector_update_with_score_verification(
426426
assert not any(r.key == "doc4" for r in results_new)
427427

428428

429+
@pytest.mark.requires_api_keys
429430
def test_store_with_memory_persistence(redis_url: str) -> None:
430431
"""Test store functionality with memory persistence.
431432

tests/test_sync.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ def model() -> ChatOpenAI:
434434
return ChatOpenAI(model="gpt-4-turbo-preview", temperature=0)
435435

436436

437+
@pytest.mark.requires_api_keys
437438
def test_sync_redis_checkpointer(
438439
tools: list[BaseTool], model: ChatOpenAI, redis_url: str
439440
) -> None:

0 commit comments

Comments
 (0)