conftest.py


Overview

The conftest.py file is a pytest configuration and fixture setup module for the InfiniFlow testing environment. It provides command-line options to customize test runs, handles user registration and authentication, manages API tokens, and configures tenant-specific settings and model integrations for testing workflows.

This file is essential for initializing the test environment, ensuring the necessary user context and system state are established before any tests are executed. It interacts with the InfiniFlow backend API to automate user lifecycle management, token generation, and model registration, facilitating smooth and repeatable test executions.


Detailed Explanation

Global Constants


pytest_addoption(parser: pytest.Parser) -> None

Purpose:
Adds custom command-line options to pytest to control test behavior.

Parameters:

Behavior:

Usage Example:

pytest --level=p1 --client-type=python_sdk

pytest_configure(config: pytest.Config) -> None

Purpose:
Configures pytest before tests start based on the command-line options.

Parameters:

Behavior:


register() -> None

Purpose:
Registers a user for testing if not already registered.

Behavior:


login() -> str

Purpose:
Logs in the registered user and retrieves an authorization token.

Returns:

Behavior:


auth pytest fixture

Scope: session

Purpose:
Provides an authenticated token for the test session.

Behavior:

Usage Example:

def test_example(auth):
    # auth is an authorization token string
    pass

token pytest fixture

Scope: session

Purpose:
Generates a new system token by calling the backend after authentication.

Parameters:

Returns:

Behavior:


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

Purpose:
Checks if a specified LLM (Large Language Model) is registered for the current user.

Parameters:

Returns:

Behavior:


add_models(auth: str) -> None

Purpose:
Registers predefined models with the backend for the authenticated user if not already present.

Parameters:

Behavior:


get_tenant_info(auth: str) -> str

Purpose:
Retrieves tenant information for the authenticated user.

Parameters:

Returns:

Behavior:


set_tenant_info pytest fixture

Scope: session, autouse=True

Purpose:
Automatically prepares tenant information and links necessary LLM and service IDs for the test session.

Parameters:

Behavior:


Important Implementation Details


Interactions with Other System Components


Usage Summary

  1. Configure test run options using command-line arguments (--level, --client-type).

  2. On pytest startup, user registration and login occur automatically.

  3. Session-scoped fixtures provide authentication tokens and tenant setup.

  4. Tests can access these fixtures to perform authenticated and tenant-aware API calls.

  5. Models are registered and tenant information is set automatically before tests run.


Mermaid Flowchart Diagram

flowchart TD
    A[pytest_addoption] --> B[pytest_configure]
    B --> C[register()]
    C --> D[login()]
    D --> E[auth fixture]
    E --> F[token fixture]
    E --> G[add_models()]
    G --> H[get_my_llms()]
    E --> I[get_tenant_info()]
    G & I --> J[set_tenant_info fixture]

Diagram Explanation:


End of Documentation for conftest.py