13445.bugfix.rst


Overview

This file documents a specific bugfix related to the `pytest.skip` function and related skipping utilities in the `pytest` testing framework. The primary purpose of this fix is to improve the **type annotations** of `pytest.skip` and its related skip functions so they are **more specification-compliant**. This enhancement aims to ensure compatibility and correctness across a wider range of type checkers, improving developer experience and code reliability when using these functions in typed Python codebases.

Type annotations are metadata that describe the expected types of function parameters and return values. Making them spec-compliant means adhering strictly to Python typing standards and conventions, which helps static analysis tools (like `mypy`, `pyright`, etc.) verify code correctness more effectively.


Detailed Explanation

Context

pytest.skip Function

`pytest.skip` is used to programmatically skip a test during execution, typically when certain conditions are met (e.g., missing dependencies, unsupported platforms).

**Before this fix:**

**After this fix:**

Parameters and Return Values

Usage Example

import pytest

def test_feature():
    if not feature_is_available():
        pytest.skip("Feature not available on this platform")
    # Test code continues only if not skipped
    assert do_something() == expected_result

This fix ensures that when running static type checks on code like above, the type checker correctly understands the behavior of `pytest.skip` and does not raise spurious errors.


Implementation Details


Interaction with Other System Components


Visual Diagram: Function and Type Annotation Relationship

flowchart TD
    A[pytest.skip(message: str) : NoReturn]
    B[pytest.skipif(condition: bool, reason: str) : Callable]
    C[pytest.mark.skip(reason: str) : Marker]

    A -->|raises skip exception| D[Control flow interruption]
    B -->|returns decorator| E[Test function]
    C -->|marks test| E

    style A fill:#f9f,stroke:#333,stroke-width:2px
    style B fill:#bbf,stroke:#333,stroke-width:2px
    style C fill:#bfb,stroke:#333,stroke-width:2px

This diagram illustrates three main skip-related functions/markers impacted by the type annotation fix:

All play crucial roles in controlling test execution flow, and their type annotations ensure clarity and correctness in their usage.


Summary


**End of Documentation**