conftest.py


Overview

The conftest.py file is a pytest configuration module used in the InfiniFlow testing suite. It provides reusable pytest fixtures that prepare, manage, and clean up test data related to chat assistant sessions. These fixtures facilitate the creation of multiple chat sessions associated with chat assistants, enabling consistent and isolated test environments for test classes or individual test functions.

The file primarily focuses on managing the lifecycle of chat sessions, ensuring that any sessions created during tests are properly cleaned up afterwards to maintain test isolation and prevent side effects.


Detailed Explanation

Imports


Fixtures

Fixtures in this file are functions decorated with @pytest.fixture. They prepare test data and define cleanup logic that runs after tests complete.


1. add_sessions_with_chat_assistant

@pytest.fixture(scope="class")
def add_sessions_with_chat_assistant(
    request: FixtureRequest,
    add_chat_assistants: tuple[DataSet, Document, list[Chat]]
) -> tuple[Chat, list[Session]]:

Functionality:

Usage Example:

def test_chat_sessions(add_sessions_with_chat_assistant):
    chat_assistant, sessions = add_sessions_with_chat_assistant
    assert len(sessions) == 5
    # further tests interacting with chat_assistant and sessions

2. add_sessions_with_chat_assistant_func

@pytest.fixture(scope="function")
def add_sessions_with_chat_assistant_func(
    request: FixtureRequest,
    add_chat_assistants: tuple[DataSet, Document, list[Chat]]
) -> tuple[Chat, list[Session]]:

Usage Example:

def test_individual_chat_session(add_sessions_with_chat_assistant_func):
    chat_assistant, sessions = add_sessions_with_chat_assistant_func
    # tests here

Important Implementation Details


Interaction with Other Components

In the broader system, this file supports test scenarios involving chat assistants and session management by offering reusable setup/teardown logic at different granularities.


Mermaid Flowchart Diagram

The following flowchart shows the relationship and workflow between the fixtures and their cleanup mechanisms in this file:

flowchart TD
    subgraph Fixtures
        A[add_sessions_with_chat_assistant (class scope)]
        B[add_sessions_with_chat_assistant_func (function scope)]
    end

    subgraph Dependencies
        C[add_chat_assistants Fixture]
        D[batch_add_sessions_with_chat_assistant Utility]
        E[Chat Assistant(s)]
        F[Session(s)]
    end

    A -->|depends on| C
    B -->|depends on| C

    C --> E
    E -->|pass to| D
    D --> F

    A --> F
    B --> F

    A -->|registers cleanup| CleanupA[Cleanup: delete_sessions]
    B -->|registers cleanup| CleanupB[Cleanup: delete_sessions]

    CleanupA --> E
    CleanupB --> E

Summary

The conftest.py file provides two pytest fixtures that automate the creation and cleanup of chat assistant sessions for testing purposes. By defining fixtures with different scopes, it supports both class-level and function-level test setups, promoting modular and maintainable test code. The fixtures leverage external utilities and SDK domain objects and ensure test environment cleanliness through robust session deletion cleanup.