From 0650e92f64b336b315794ccb1c9512ba500abbeb Mon Sep 17 00:00:00 2001 From: Teo Date: Sun, 12 Jan 2025 01:18:42 +0100 Subject: [PATCH] Isolate vcr_config import into tests/integration Signed-off-by: Teo --- tests/integration/conftest.py | 2 +- tests/unit/conftest.py | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 05e90a34..70beceb9 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -1,7 +1,7 @@ import pytest import agentops - +from tests.fixtures.vcr import vcr_config @pytest.fixture def agentops_session(): diff --git a/tests/unit/conftest.py b/tests/unit/conftest.py index 8690f82b..0b31a25a 100644 --- a/tests/unit/conftest.py +++ b/tests/unit/conftest.py @@ -8,7 +8,6 @@ import agentops from agentops.singleton import clear_singletons from tests.fixtures.event import llm_event_spy -from tests.fixtures.vcr import vcr_config # Common JWT tokens used across tests JWTS = ["some_jwt", "some_jwt2", "some_jwt3"] @@ -24,6 +23,38 @@ def setup_teardown(): agentops.end_all_sessions() # teardown part +# @contextlib.contextmanager +# @pytest.fixture(autouse=True) +# def mock_req() -> Iterator[requests_mock.Mocker]: +# """ +# Centralized request mocking for all tests. +# Mocks common API endpoints with standard responses. +# """ +# with requests_mock.Mocker() as m: +# url = "https://api.agentops.ai" +# +# # Mock API endpoints +# m.post(url + "/v2/create_events", json={"status": "ok"}) +# m.post(url + "/v2/developer_errors", json={"status": "ok"}) +# m.post(url + "/v2/update_session", json={"status": "success", "token_cost": 5}) +# m.post("https://pypi.org/pypi/agentops/json", status_code=404) +# +# # Use iterator for JWT tokens in session creation +# jwt_tokens = iter(JWTS) +# +# def create_session_response(request, context): +# context.status_code = 200 +# try: +# return {"status": "success", "jwt": next(jwt_tokens)} +# except StopIteration: +# return {"status": "success", "jwt": "some_jwt"} # Fallback JWT +# +# m.post(url + "/v2/create_session", json=create_session_response) +# m.post(url + "/v2/reauthorize_jwt", json={"status": "success", "jwt": "some_jwt"}) +# +# yield m + + @pytest.fixture(scope="session") def api_key() -> str: """Standard API key for testing"""