conftest.py


Overview

The conftest.py file is a pytest configuration module designed to provide reusable fixtures and helper functions for testing the InfiniFlow project, specifically focusing on chat assistant and document parsing workflows. It facilitates setup and teardown operations for tests that require:

This file integrates with the project's API clients and utility functions to streamline test preparation and cleanup, ensuring test isolation and reliability.


Detailed Explanation

Imports


Functions and Fixtures

1. condition(_auth, _dataset_id)

@wait_for(30, 1, "Document parsing timeout")
def condition(_auth, _dataset_id):
    res = list_documnets(_auth, _dataset_id)
    for doc in res["data"]["docs"]:
        if doc["run"] != "DONE":
            return False
    return True

2. add_chat_assistants_func(request, get_http_api_auth, add_document)

@pytest.fixture(scope="function")
def add_chat_assistants_func(request, get_http_api_auth, add_document):
    def cleanup():
        delete_chat_assistants(get_http_api_auth)

    request.addfinalizer(cleanup)

    dataset_id, document_id = add_document
    parse_documnets(get_http_api_auth, dataset_id, {"document_ids": [document_id]})
    condition(get_http_api_auth, dataset_id)

    chat_assistant_ids = []
    for i in range(5):
        res = create_chat_assistant(get_http_api_auth, {"name": f"test_chat_assistant_{i}", "dataset_ids": [dataset_id]})
        chat_assistant_ids.append(res["data"]["id"])

    return dataset_id, document_id, chat_assistant_ids
def test_chat_assistant_functionality(add_chat_assistants_func):
    dataset_id, document_id, chat_assistant_ids = add_chat_assistants_func
    # Perform test assertions or API calls with created chat assistants
    assert len(chat_assistant_ids) == 5

Important Implementation Details


Interaction with Other System Components


Mermaid Flowchart Diagram

flowchart TD
    A[add_chat_assistants_func Fixture]
    B[add_document Fixture]
    C[get_http_api_auth Fixture]
    D[parse_documnets()]
    E[condition() with wait_for]
    F[create_chat_assistant() x5]
    G[delete_chat_assistants() Cleanup]

    A --> B
    A --> C
    A --> D
    D --> E
    E --> F
    A --> G

Explanation:


Summary

conftest.py is a critical pytest configuration file that enables robust testing of chat assistant and document parsing features in the InfiniFlow project. By providing a reusable fixture that handles setup and teardown, it simplifies test development and ensures tests run against a clean, predictable environment. Its use of polling and cleanup patterns exemplifies best practices in integration testing asynchronous backend workflows.