freeze_support.py

Overview

`freeze_support.py` provides utility functions designed to assist freezing tools (such as cx_Freeze) in identifying all internal modules used by the `pytest` testing framework. Freezing tools bundle Python applications into standalone executables by including all necessary modules and dependencies. This file specifically helps ensure that all relevant `pytest` submodules are detected and included during the freezing process.

The primary functionality centers around recursively enumerating all modules within the `_pytest` package, returning a comprehensive list of module names that freezing tools can then incorporate.


Detailed Documentation

Function: freeze_includes() -> list[str]

Returns a list of fully qualified module names used by `pytest` that should be included by the freezing tool cx_Freeze.


Function: _iter_all_modules(package: str | types.ModuleType, prefix: str = "") -> Iterator[str]

Recursively iterates over the names of all modules within a given package, yielding their fully qualified names.


Important Implementation Details


Interaction with Other System Components


Visual Diagram

The following Mermaid flowchart illustrates the workflow and relationships between the main functions in this file:

flowchart TD
    A[freeze_includes()] --> B[_iter_all_modules(package=_pytest)]
    B --> C{Is item a package?}
    C -- Yes --> B
    C -- No --> D[Yield fully qualified module name]
    D --> E[Collect all module names into list]
    E --> F[Return list of module names]

Summary

`freeze_support.py` is a small but essential utility to facilitate the freezing of the `pytest` package by programmatically enumerating all internal modules. It ensures that freezing tools can gather the complete set of modules required for a standalone executable, avoiding missing dependencies that could cause runtime errors. The recursive discovery implemented via `_iter_all_modules` is a robust solution for dynamic module inclusion, adaptable to changes in `pytest` internals without manual updates.