conftest.py


Overview

The conftest.py file is a configuration module used by the pytest testing framework to provide reusable fixtures for test cases. In this context, it supplies fixtures that automate the setup and teardown of dataset resources for tests that require interacting with datasets through an HTTP API. These fixtures create datasets before tests run and ensure their cleanup after tests complete, thereby maintaining test isolation and preventing resource leaks.


Detailed Explanation

Imports


Fixtures

Fixtures in this file provide pre-test setup and post-test cleanup for datasets in two different scopes.


1. add_datasets

def test_dataset_processing(add_datasets):
    # add_datasets provides 5 datasets created before the test runs
    assert len(add_datasets) == 5
    # perform tests on these datasets

2. add_datasets_func

def test_single_dataset_operation(add_datasets_func):
    # add_datasets_func provides 3 datasets created before each test function
    assert len(add_datasets_func) == 3
    # test code utilizing these datasets

Important Implementation Details


Interaction with Other System Parts


Mermaid Diagram

flowchart TD
    A[conftest.py] --> B[add_datasets (class scope)]
    A --> C[add_datasets_func (function scope)]

    B --> D[Calls batch_create_datasets(HttpApiAuth, 5)]
    B --> E[Registers cleanup: delete_datasets(HttpApiAuth, {"ids": None})]

    C --> F[Calls batch_create_datasets(HttpApiAuth, 3)]
    C --> G[Registers cleanup: delete_datasets(HttpApiAuth, {"ids": None})]

    subgraph External Dependencies
        H[HttpApiAuth fixture]
        I[common.batch_create_datasets]
        J[common.delete_datasets]
    end

    D --> I
    E --> J
    F --> I
    G --> J

    B --> H
    C --> H

Summary

conftest.py provides two pytest fixtures for managing dataset lifecycle in tests:

These fixtures leverage centralized dataset creation and deletion utilities for consistent, isolated testing of features relying on datasets managed via an HTTP API.

This setup promotes clean, maintainable test code and reliable test execution within the InfiniFlow testing framework.