I'm building a RAG (Retrieval-Augmented Generation) chatbot using LangChain, Gemini API, and Qdrant, with a Streamlit frontend. I want to write unit tests for the app using pytest, and I’m trying to use fixtures to mock the retriever and LLM components.
Here's an example of what I'm trying to do:
import pytest
from my_rag_app.rag_chain import get_rag_chain
@pytest.fixture
def mock_retriever():
class DummyRetriever:
def get_relevant_documents(self, query):
return [{"page_content": "Mock content"}]
return DummyRetriever()
def test_rag_chain(mock_retriever):
rag_chain = get_rag_chain(mock_retriever)
response = rag_chain.invoke("What is RAG?")
assert "Mock content" in response["result"]
But I’m getting errors like:
TypeError: test_rag_chain() missing 1 required positional argument: 'mock_retriever'
I'm building a RAG (Retrieval-Augmented Generation) chatbot using LangChain, Gemini API, and Qdrant, with a Streamlit frontend. I want to write unit tests for the app using pytest, and I’m trying to use fixtures to mock the retriever and LLM components.
My Question is:
What’s the correct way to use pytest fixtures with LangChain pipelines or custom retrievers?
Do I need to mock more than just the retriever (like Gemini LLM or embeddings)?
Is there a recommended testing strategy for RAG pipelines involving LangChain and Qdrant?
Any advice or best practices would be appreciated. Thanks!