Skip to content

Commit 6716bcc

Browse files
committed
Integrated pytest-recording into conftest.py
1 parent e104c91 commit 6716bcc

File tree

5 files changed

+27
-0
lines changed

5 files changed

+27
-0
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ repos:
3636
args:
3737
- --word-list=.secrets.allowlist
3838
- --exclude-files=.secrets.baseline$
39+
exclude: tests/cassettes
3940
- repo: https://github.com/jumanjihouse/pre-commit-hooks
4041
rev: 3.0.0
4142
hooks:

.secrets.allowlist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
authorization
2+
x-api-key

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ tests-root = "tests"
7474
check-filenames = true
7575
check-hidden = true
7676
ignore-words-list = "astroid,ser"
77+
skip = "tests/cassettes/*"
7778

7879
[tool.mypy]
7980
# Type-checks the interior of functions without type annotations.

tests/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import pathlib
12
from enum import StrEnum
23

34

@@ -6,3 +7,7 @@ class CILLMModelNames(StrEnum):
67

78
ANTHROPIC = "claude-3-haiku-20240307" # Cheap and not Anthropic's cutting edge
89
OPENAI = "gpt-4o-mini-2024-07-18" # Cheap and not OpenAI's cutting edge
10+
11+
12+
TESTS_DIR = pathlib.Path(__file__).parent
13+
CASSETTES_DIR = TESTS_DIR / "cassettes"

tests/conftest.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import random
3+
from typing import Any
34

45
import numpy as np
56
import pytest
@@ -8,6 +9,8 @@
89

910
from ldp.utils import configure_log_levels
1011

12+
from . import CASSETTES_DIR
13+
1114
IN_GITHUB_ACTIONS: bool = os.getenv("GITHUB_ACTIONS") == "true"
1215

1316

@@ -35,3 +38,18 @@ def set_seed(seed: int | None) -> None:
3538
def fixture_seed_zero() -> None:
3639
"""Set a 0 seed to minimize the chances of test flakiness."""
3740
set_seed(0)
41+
42+
43+
OPENAI_API_KEY_HEADER = "authorization"
44+
ANTHROPIC_API_KEY_HEADER = "x-api-key"
45+
46+
47+
@pytest.fixture(scope="session", name="vcr_config")
48+
def fixture_vcr_config() -> dict[str, Any]:
49+
return {
50+
"filter_headers": [OPENAI_API_KEY_HEADER, ANTHROPIC_API_KEY_HEADER, "cookie"],
51+
"record_mode": "once",
52+
"match_on": ["method", "host", "path", "query"],
53+
"allow_playback_repeats": True,
54+
"cassette_library_dir": str(CASSETTES_DIR),
55+
}

0 commit comments

Comments
 (0)