conftest.py


Overview

conftest.py is a Pytest configuration and fixtures file designed for integration testing within the InfiniFlow project. It provides reusable test fixtures and utility functions that simplify setting up the test environment, particularly focusing on preparing datasets, documents, and chat assistant instances needed to test the RAGFlow system's chat and document parsing functionality.

Key functionalities include:

This file primarily enables reliable, repeatable integration tests by managing asynchronous operations and resource lifecycle within the RAGFlow environment.


Detailed Components

Imports


Function: condition

@wait_for(30, 1, "Document parsing timeout")
def condition(_dataset: DataSet) -> bool:

Purpose

Checks whether all documents within a given dataset have finished parsing by verifying that each document's run status is "DONE". This function is decorated with wait_for to retry this condition every 1 second for up to 30 seconds, raising a timeout error if the condition is not met.

Parameters

Returns

Usage Example

condition(dataset)  # Will wait until all documents in dataset are parsed or timeout occurs

Implementation Details


Fixture: add_chat_assistants_func

@pytest.fixture(scope="function")
def add_chat_assistants_func(
    request: FixtureRequest,
    client: RAGFlow,
    add_document: tuple[DataSet, Document]
) -> tuple[DataSet, Document, list[Chat]]:

Purpose

Provides a test fixture that prepares and returns a dataset, a parsed document, and a list of chat assistants for use in test functions.

This fixture handles:

Parameters

Returns

Usage Example

def test_chat_functionality(add_chat_assistants_func):
    dataset, document, chat_assistants = add_chat_assistants_func
    # perform test assertions and interactions with chat_assistants

Implementation Details


Important Implementation Details


Interaction with Other Parts of the System


Visual Diagram

flowchart TD
    subgraph Fixtures & Functions
        condition["condition(_dataset: DataSet)"]
        add_chat_assistants_func["add_chat_assistants_func(request, client, add_document)"]
    end

    subgraph External Modules
        wait_for["wait_for(timeout=30s, interval=1s)"]
        batch_create["batch_create_chat_assistants(client, 5)"]
        client["RAGFlow client"]
        add_document["add_document fixture\n(DataSet, Document)"]
    end

    condition -- decorated by --> wait_for
    add_chat_assistants_func --> add_document
    add_chat_assistants_func --> client
    add_chat_assistants_func --> condition
    add_chat_assistants_func --> batch_create
    add_chat_assistants_func -- cleanup --> client

    condition -->|checks| client

Summary

conftest.py is a key testing support file in the InfiniFlow project that provides:

This file is integral to the testing workflow for components relying on document ingestion and chat assistant creation in the RAGFlow system, enabling consistent and reliable integration tests.


End of Documentation for conftest.py