conftest.py

Overview

The [conftest.py](/projects/286/67243) file is a configuration and extension point for the `pytest` testing framework. It customizes test collection behavior to support a non-standard project structure where test files are explicitly listed in a manifest (`manifest.json`) instead of being discovered by default file pattern matching.

Specifically, this file defines a custom `ManifestDirectory` collector class that reads a `manifest.json` file in a directory and collects test files listed inside it. It also implements the `pytest_collect_directory` hook to enable `pytest` to use the custom collector automatically when it finds a `manifest.json`.

This approach allows finer control over which test files are included in test runs, enabling scenarios like selective or dynamic test suite definitions.


Detailed Explanation

Class: ManifestDirectory

A subclass of [pytest.Directory](/projects/286/67393) which overrides the default directory collection behavior.

Purpose

Methods

collect(self)

Function: pytest_collect_directory(path, parent)


Important Implementation Details


Interaction with Other Parts of the System


Visual Diagram

flowchart TD
    A[pytest_collect_directory Hook]
    B[ManifestDirectory Class]
    C[manifest.json File]
    D[ihook.pytest_collect_file]
    E[Test Files Listed in manifest.json]

    A -->|detects manifest.json| B
    B -->|reads manifest.json| C
    B -->|for each file| D
    C -->|provides file list| B
    D -->|collect test nodes for| E

Summary

This [conftest.py](/projects/286/67243) customizes pytest’s collection logic to support a manifest-driven test discovery mechanism. It defines a new directory collector class that parses a `manifest.json` file to enumerate test files, and registers a hook to activate this collector automatically. This setup enables explicit control over test file inclusion, improving flexibility for complex or non-standard project layouts while fully integrating with pytest’s core features.