conftest.py


Overview

conftest.py is a pytest configuration and fixture definition file used within the InfiniFlow testing suite. Its primary purpose is to set up reusable test fixtures, configure test execution parameters, and provide helper utilities for testing the InfiniFlow RAG (Retrieval-Augmented Generation) flow system.

This file facilitates testing by:

It integrates closely with common test utilities and InfiniFlow’s API client libraries to orchestrate end-to-end test scenarios.


Detailed Explanation

Constants


pytest_addoption(parser: pytest.Parser) -> None

Adds a command-line option --level to pytest to select the test run level.


pytest_configure(config: pytest.Config) -> None

Configures pytest based on CLI options, applying marker expressions to filter tests.


condition(_auth, _dataset_id) -> bool

A polling condition function decorated with @wait_for to check if document parsing has completed.


Fixtures

pytest fixtures declared with various scopes (function, class, session) to provide reusable test components.

get_http_api_auth(get_api_key_fixture) -> RAGFlowHttpApiAuth

clear_datasets(request, get_http_api_auth)

clear_chat_assistants(request, get_http_api_auth)

clear_session_with_chat_assistants(request, get_http_api_auth, add_chat_assistants)

generate_test_files(request, tmp_path) -> dict

ragflow_tmp_dir(request, tmp_path_factory) -> pathlib.Path

add_dataset(request, get_http_api_auth) -> str

add_dataset_func(request, get_http_api_auth) -> str

add_document(get_http_api_auth, add_dataset, ragflow_tmp_dir) -> tuple[str, str]

add_chunks(get_http_api_auth, add_document) -> tuple[str, str, list[str]]

add_chat_assistants(request, get_http_api_auth, add_document) -> tuple[str, str, list[str]]


Important Implementation Details


Interaction with Other System Components


Visual Diagram

The following Mermaid flowchart describes the main functions and fixtures in conftest.py and their relationships, focusing on resource setup and cleanup workflows.

flowchart TD
    A[pytest CLI: --level option] --> B[pytest_addoption]
    B --> C[pytest_configure]
    C --> D{MARKER_EXPRESSIONS}
    D -->|Set markexpr| E[Filter tests by level]

    subgraph Authentication
        F[get_http_api_auth]
    end

    subgraph Dataset Management
        G[add_dataset]
        H[add_dataset_func]
        I[clear_datasets]
    end

    subgraph Document Management
        J[add_document]
        K[add_chunks]
        L[generate_test_files]
    end

    subgraph Chat Assistant Management
        M[add_chat_assistants]
        N[clear_chat_assistants]
        O[clear_session_with_chat_assistants]
    end

    subgraph Utilities
        P[condition (wait_for)]
    end

    F --> G
    F --> H
    G --> J
    J --> K
    J --> M
    K --> P
    M --> O

    I -.cleanup after test .-> G
    N -.cleanup after test .-> M
    O -.cleanup after test .-> M

    L --> J

    style A fill:#f9f,stroke:#333,stroke-width:2px
    style F fill:#bbf,stroke:#333,stroke-width:1px
    style G fill:#bbf,stroke:#333,stroke-width:1px
    style H fill:#bbf,stroke:#333,stroke-width:1px
    style I fill:#fbb,stroke:#333,stroke-width:1px,stroke-dasharray: 5 5
    style J fill:#bbf,stroke:#333,stroke-width:1px
    style K fill:#bbf,stroke:#333,stroke-width:1px
    style L fill:#bbf,stroke:#333,stroke-width:1px
    style M fill:#bbf,stroke:#333,stroke-width:1px
    style N fill:#fbb,stroke:#333,stroke-width:1px,stroke-dasharray: 5 5
    style O fill:#fbb,stroke:#333,stroke-width:1px,stroke-dasharray: 5 5
    style P fill:#ffb,stroke:#333,stroke-width:1px

Summary

conftest.py is a critical support file for the InfiniFlow test suite, enabling flexible test configuration and robust setup/teardown of datasets, documents, and chat assistants. It abstracts common testing concerns such as authentication, file generation, resource cleanup, and asynchronous state waiting into reusable fixtures and utilities, making test code simpler and more maintainable.

This file interacts tightly with shared common modules and utility libraries to execute realistic integration-style tests against the InfiniFlow HTTP API. Its design leverages pytest’s powerful fixture and configuration system to provide a scalable and configurable testing infrastructure.