deprecated.py

Overview

The `deprecated.py` module centralizes deprecation warnings and related code snippets used throughout the pytest codebase. Its primary purpose is to track features, APIs, or plugins that are planned to be removed in future pytest releases. By consolidating all deprecation messages and warning definitions into one file, it simplifies maintenance and ensures consistent communication about deprecated functionality across the project.

This module defines a collection of warning constants, mostly instances of [PytestWarning](/projects/286/67359) or `UnformattedWarning`, representing various deprecations. It also provides utility functions to facilitate the controlled issuance of deprecation warnings during runtime.


Contents


Detailed Explanations

Constants

Each constant in this module is a warning message related to deprecated functionality. They are designed to be raised via Python’s warning system and include references to official documentation for further guidance.


DEPRECATED_EXTERNAL_PLUGINS

DEPRECATED_EXTERNAL_PLUGINS: set[str]

YIELD_FIXTURE

YIELD_FIXTURE = PytestDeprecationWarning(...)

PRIVATE

PRIVATE = PytestDeprecationWarning(...)

HOOK_LEGACY_PATH_ARG

HOOK_LEGACY_PATH_ARG = UnformattedWarning(...)

NODE_CTOR_FSPATH_ARG

NODE_CTOR_FSPATH_ARG = UnformattedWarning(...)

HOOK_LEGACY_MARKING

HOOK_LEGACY_MARKING = UnformattedWarning(...)

MARKED_FIXTURE

MARKED_FIXTURE = PytestRemovedIn9Warning(...)

Functions

check_ispytest

def check_ispytest(ispytest: bool) -> None:
def _my_private_function(arg1, *, _ispytest: bool = False):
    check_ispytest(_ispytest)
    # Function implementation

# Internal call (allowed)
_my_private_function("value", _ispytest=True)

# External call (triggers warning)
_my_private_function("value")

Important Implementation Details


Interaction with Other Parts of the System


Visual Diagram

classDiagram
    class deprecated {
        <<module>>
        +DEPRECATED_EXTERNAL_PLUGINS: set[str]
        +YIELD_FIXTURE: PytestDeprecationWarning
        +PRIVATE: PytestDeprecationWarning
        +HOOK_LEGACY_PATH_ARG: UnformattedWarning
        +NODE_CTOR_FSPATH_ARG: UnformattedWarning
        +HOOK_LEGACY_MARKING: UnformattedWarning
        +MARKED_FIXTURE: PytestRemovedIn9Warning
        +check_ispytest(ispytest: bool) void
    }
    deprecated ..> PytestDeprecationWarning : uses
    deprecated ..> PytestRemovedIn9Warning : uses
    deprecated ..> UnformattedWarning : uses

Summary

The `deprecated.py` module is a centralized repository for deprecation warnings used throughout pytest. It simplifies maintenance by consolidating all deprecation messages and related utilities into a single place, standardizes how warnings are issued, and supports pytest’s internal API encapsulation. This approach improves the user experience by providing clear guidance on deprecated features and smooth migration to newer APIs.