conftest.py

Overview

The conftest.py file is a configuration and fixture definition module used by the pytest testing framework within the InfiniFlow project. Its primary purpose is to define reusable test fixtures that manage the lifecycle of document data in the system, including setup and teardown operations. Specifically, it provides fixtures that create and upload documents to datasets before tests run and clean up (delete) those documents afterward to ensure test isolation and prevent side effects.

This file focuses on preparing datasets with uploaded documents for testing HTTP API endpoints related to document management. It integrates with external helper functions (bulk_upload_documents and delete_documents) from a common module to perform the actual upload and deletion operations.

Detailed Descriptions

Imports


Fixtures

All fixtures use the pytest.fixture decorator and are designed to be used in test functions or test classes. They automate setup and teardown by uploading documents to datasets before tests run and deleting those documents after tests complete.


1. add_document_func

@pytest.fixture(scope="function")
def add_document_func(request, HttpApiAuth, add_dataset, ragflow_tmp_dir):
    ...
def test_single_document(add_document_func):
    dataset_id, document = add_document_func
    # Use dataset_id and document in test assertions

2. add_documents

@pytest.fixture(scope="class")
def add_documents(request, HttpApiAuth, add_dataset, ragflow_tmp_dir):
    ...
@pytest.mark.usefixtures("add_documents")
class TestDocumentBatch:
    def test_documents_count(self, add_documents):
        dataset_id, documents = add_documents
        assert len(documents) == 5

3. add_documents_func

@pytest.fixture(scope="function")
def add_documents_func(request, HttpApiAuth, add_dataset_func, ragflow_tmp_dir):
    ...
def test_documents_set(add_documents_func):
    dataset_id, documents = add_documents_func
    assert len(documents) == 3

Important Implementation Details


Interaction with Other Parts of the System


Visual Diagram

The following Mermaid flowchart illustrates the relationships and workflow between the fixtures and key functions in this file:

flowchart TD
    subgraph Fixtures
        A[add_document_func (function scope)]
        B[add_documents (class scope)]
        C[add_documents_func (function scope)]
    end

    subgraph Dataset Creation
        D[add_dataset]
        E[add_dataset_func]
    end

    subgraph Document Management
        F[bulk_upload_documents]
        G[delete_documents]
    end

    A --> D
    B --> D
    C --> E

    A --> F
    B --> F
    C --> F

    A --> G
    B --> G
    C --> G

    style A fill:#f9f,stroke:#333,stroke-width:1px
    style B fill:#f9f,stroke:#333,stroke-width:1px
    style C fill:#f9f,stroke:#333,stroke-width:1px

Summary

conftest.py defines critical pytest fixtures that prepare datasets with documents for testing the InfiniFlow system. It automates uploading documents and cleaning them up to ensure reliable, isolated, and repeatable tests. The file leverages existing dataset fixtures and common utilities for upload and deletion, abstracting test setup complexity and promoting reuse across the test suite.