setupplan.py

Overview

The [setupplan.py](/projects/286/67433) file is a utility extension for the pytest testing framework that introduces a command-line option to **display the planned fixture and test setup sequence without actually executing any tests or fixture setups**. This is useful for debugging and understanding the order and dependencies of fixtures and tests in a pytest session.

Key functionality includes:

This file leverages pytest’s hook system to integrate seamlessly with pytest’s lifecycle and configuration processing.


Detailed Explanation

Functions


pytest_addoption(parser: Parser) -> None

**Purpose:** Registers a new command-line option group "debugconfig" and adds the `--setupplan` / [--setup-plan](/projects/286/67223) flag to pytest's CLI options.

**Parameters:**

**Returns:**

**Behavior:**

**Usage Example:**

pytest --setupplan

pytest_fixture_setup(fixturedef: FixtureDef[object], request: SubRequest) -> object | None

**Purpose:** A hook implementation that intercepts fixture setup calls. If the `--setupplan` option is enabled, this function prevents actual fixture execution by returning a dummy cached result.

**Parameters:**

**Returns:**

**Behavior:**

**Usage Context:** Called internally by pytest during fixture setup. Not typically called manually.


pytest_cmdline_main(config: Config) -> int | ExitCode | None

**Purpose:** A hook implementation that modifies pytest configuration options early in the command-line main phase, aligning other internal options with `--setupplan`.

**Parameters:**

**Returns:**

**Behavior:**


Important Implementation Details


Interaction with Other System Components


Usage Summary

To use this feature, simply run pytest with:

pytest --setupplan

This will output the plan of fixtures and tests pytest would execute, but will **not actually run** the tests or fixture setup code. This is helpful to understand dependencies and order of test setup.


Visual Diagram

classDiagram
    class SetupPlanPlugin {
        +pytest_addoption(parser: Parser) void
        +pytest_fixture_setup(fixturedef: FixtureDef, request: SubRequest) object | None
        +pytest_cmdline_main(config: Config) int | ExitCode | None
    }

    SetupPlanPlugin ..> Parser : uses
    SetupPlanPlugin ..> FixtureDef : uses
    SetupPlanPlugin ..> SubRequest : uses
    SetupPlanPlugin ..> Config : uses

Summary

The [setupplan.py](/projects/286/67433) file is a pytest plugin extension that adds a `--setupplan` option to show the planned fixture and test execution order without running anything. It achieves this by hooking into pytest’s fixture setup and command-line main phases, disabling actual fixture execution and adjusting configuration options to simulate a setup-only dry run. This tool is valuable for debugging and inspecting test dependencies in complex pytest test suites.


End of Documentation for setupplan.py