conftest.py

Overview

conftest.py is a configuration and utility file used in the testing framework based on pytest for the InfiniFlow project. It provides fixtures and helper functions to facilitate user registration, login, API key retrieval, model setup, and tenant configuration in a test environment. This file automates the setup of authentication tokens and environment prerequisites required for running integration and system tests against the InfiniFlow backend services.

Key responsibilities:


Detailed Documentation

Environment Variables


Functions

generate_email() -> str

Generates a fixed test email address.


register() -> None

Registers a new user account using the configured email and password.


login() -> str

Authenticates the test user and retrieves the authentication token.


get_my_llms(auth: str, name: str) -> bool

Checks if a specified LLM model is already added for the authenticated user.


add_models(auth: str) -> None

Adds predefined LLM models to the user's account if not already present.


get_tenant_info(auth: str) -> str

Retrieves the tenant ID associated with the authenticated user.


Pytest Fixtures

These fixtures are session-scoped to provide setup once per test session.

get_api_key_fixture() -> str

get_auth() -> str

get_email() -> str


set_tenant_info(get_auth) -> None


Implementation Details and Algorithms


Interactions with Other System Components


Usage Example in a Test File

def test_some_api_call(get_auth, get_api_key_fixture):
    auth = get_auth
    token = get_api_key_fixture
    headers = {"Authorization": auth}

    response = requests.get(f"{HOST_ADDRESS}/v1/some/endpoint", headers=headers)
    assert response.status_code == 200

Mermaid Flowchart: Workflow of Main Functions and Fixtures

flowchart TD
    A[Start: Test Session Begins]
    A --> B[Fixture: get_auth()]
    B --> C[register() user]
    C --> D[login() user]
    D --> E[Fixture: get_api_key_fixture()]
    E --> F[Request /v1/system/new_token]
    D --> G[Fixture: set_tenant_info()]
    G --> H[add_models()]
    H --> I[get_my_llms() check models]
    I --> J[Add missing models]
    G --> K[get_tenant_info()]
    G --> L[Set tenant info via /v1/user/set_tenant_info]
    L --> M[Tests run with authenticated context]

    style A fill:#f9f,stroke:#333,stroke-width:2px
    style M fill:#bbf,stroke:#333,stroke-width:2px

Summary

conftest.py is a critical support file for the InfiniFlow test suite, automating user setup, authentication, model configuration, and tenant context establishment to enable seamless integration testing. It tightly integrates with backend APIs and external LLM services, ensuring tests run in a correctly initialized state. The fixtures provided here are foundational for any tests requiring authenticated access and configured resources.