Skip to content

Commit

Permalink
chg: first working vcr test pytest-recording
Browse files Browse the repository at this point in the history
  • Loading branch information
bossjones committed Aug 16, 2024
1 parent fbb77f9 commit 3324b03
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion tests/services/test_chroma_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
if TYPE_CHECKING:
from unittest.mock import AsyncMock, MagicMock, NonCallableMagicMock

from _pytest.capture import CaptureFixture
from _pytest.fixtures import FixtureRequest
from _pytest.logging import LogCaptureFixture
from _pytest.monkeypatch import MonkeyPatch
Expand Down Expand Up @@ -974,14 +975,19 @@ def dummy_chroma_db(mocker) -> Chroma:
# @pytest.mark.vcr()
# @pytest.mark.vcr(allow_playback_repeats=True)
@pytest.mark.vcr(allow_playback_repeats=True, match_on=["request_matcher"], ignore_localhost=False)
def test_search_db_returns_relevant_documents(dummy_chroma_db: Chroma, caplog: LogCaptureFixture):
def test_search_db_returns_relevant_documents(
dummy_chroma_db: Chroma, caplog: LogCaptureFixture, capsys: CaptureFixture, vcr
):
"""
Test that search_db returns relevant documents when found.
This test verifies that the `search_db` function returns a list of
relevant documents and their scores when a match is found in the database.
"""
caplog.set_level(logging.DEBUG)
# import bpdb

# bpdb.set_trace()
db = dummy_chroma_db
results = search_db(db, "test query")
query_text = "test query"
Expand All @@ -992,6 +998,12 @@ def test_search_db_returns_relevant_documents(dummy_chroma_db: Chroma, caplog: L

# FIXME: # assert results == expected_results

# out, err = capsys.readouterr()
# with capsys.disabled():
# import rich
# rich.inspect(vcr, all=True)

assert vcr.play_count == 1
# assert results == expected_results
# wait for logging to finish runnnig
# await LOGGER.complete()
Expand Down

0 comments on commit 3324b03

Please sign in to comment.