conftest.py


Overview

The conftest.py file provides pytest fixtures for managing chat assistant sessions within the InfiniFlow testing framework. It is designed to help test cases by setting up and tearing down multiple chat assistant sessions automatically, reducing boilerplate code and ensuring resource cleanup after tests run. The fixtures handle creation of chat sessions linked to chat assistants, and ensure these sessions are deleted after tests complete.

This file interacts closely with utility functions imported from the common module, which encapsulate HTTP API calls to create and delete chat sessions. It also relies on other fixtures (such as get_http_api_auth and add_chat_assistants) which provide authentication and chat assistant setup.


Detailed Explanations

Imports


Fixtures

1. add_sessions_with_chat_assistant

Parameters
Returns
Usage Example
def test_example(add_sessions_with_chat_assistant):
    chat_assistant_id, session_ids = add_sessions_with_chat_assistant
    assert len(session_ids) == 5
    # Interact with sessions in tests here
Implementation Details

2. add_sessions_with_chat_assistant_func

Parameters
Returns
Usage Example
def test_individual(add_sessions_with_chat_assistant_func):
    chat_assistant_id, session_ids = add_sessions_with_chat_assistant_func
    assert len(session_ids) == 5
    # Test with fresh sessions per test function
Implementation Details

Important Implementation Details


Interaction with Other Parts of the System


Visual Diagram

This file is a utility file mainly defining fixtures and their workflows. The diagram below shows the flow and relationships between the main functions and fixtures within conftest.py and their interactions.

flowchart TD
    A[add_chat_assistants Fixture] --> B[get_chat_assistant_ids]
    B --> C[add_sessions_with_chat_assistant]
    B --> D[add_sessions_with_chat_assistant_func]
    C --> E[create_session_with_chat_assistant (5 times)]
    D --> F[create_session_with_chat_assistant (5 times)]
    C --> G[register cleanup finalizer]
    D --> G
    G --> H[delete_session_with_chat_assistants for each chat_assistant_id]
    subgraph Usage in Tests
        C --> I[Test Class uses add_sessions_with_chat_assistant]
        D --> J[Test Function uses add_sessions_with_chat_assistant_func]
    end

Summary

The conftest.py file defines two pytest fixtures that facilitate the creation and cleanup of multiple chat assistant sessions to be used in testing. By abstracting session management and cleanup, it enables tests to focus on core logic while maintaining environment stability and isolation. Its effective use of pytest's fixture scopes and finalizers ensures robust, repeatable, and clean test runs within the InfiniFlow project.