conftest.py


Overview

conftest.py is a pytest configuration and fixture file used within the InfiniFlow testing framework. Its primary role is to provide reusable test fixtures and helper functions that facilitate automated testing of document parsing and chunk management workflows in the InfiniFlow system.

This file defines:

By encapsulating these common setup and teardown operations in conftest.py, the file enhances test modularity, reliability, and maintainability.


Detailed Explanation

Imported Modules and Functions


Function: condition

@wait_for(30, 1, "Document parsing timeout")
def condition(_auth, _kb_id):
    ...
# Wait until all documents are parsed with run "3"
condition(auth_token, kb_id)

Fixture: add_chunks_func

@pytest.fixture(scope="function")
def add_chunks_func(request, WebApiAuth, add_document):
    ...
def test_chunk_processing(add_chunks_func):
    kb_id, document_id, chunk_ids = add_chunks_func
    # Test logic using the document and chunks
def cleanup():
    res = list_chunks(WebApiAuth, {"doc_id": document_id})
    chunk_ids = [chunk["chunk_id"] for chunk in res["data"]["chunks"]]
    delete_chunks(WebApiAuth, {"doc_id": document_id, "chunk_ids": chunk_ids})

Ensures no leftover data remains after tests, maintaining test environment isolation.


Important Implementation Details and Algorithms


Interaction with Other Parts of the System


Mermaid Diagram

The following flowchart illustrates the main functional workflow and relationships between the components and functions in this file:

flowchart TD
    A[Start: Test Function Requests add_chunks_func Fixture]
    B[add_document Fixture -> Returns kb_id, document_id]
    C[parse_documents(WebApiAuth, doc_ids=[document_id], run="1")]
    D[condition(WebApiAuth, kb_id) - Waits for Parsing Completion (run == "3")]
    E[batch_add_chunks(WebApiAuth, document_id, 4) -> Returns chunk_ids]
    F[sleep(1) - Wait for consistency]
    G[Return (kb_id, document_id, chunk_ids) to Test]
    H[After Test: Cleanup Function Called]
    I[list_chunks -> Get chunk_ids]
    J[delete_chunks -> Delete chunks]

    A --> B --> C --> D --> E --> F --> G
    G --> H --> I --> J

Summary

conftest.py acts as a foundational pytest support file that encapsulates common test setup and teardown logic related to document parsing and chunk management in InfiniFlow. Through a combination of waiting conditions, chunk lifecycle management, and cleanup routines, it ensures reliable and isolated testing of document-related features. Its integration with the common and utils modules, and pytest's fixture system, makes it a critical part of the test infrastructure.