release-2.2.0.rst

Overview

This file contains the release notes and changelog for **pytest version 2.2.0**, a popular Python testing tool also known as *py.test*. It documents the new features, improvements, bug fixes, and important compatibility notes introduced in this release. The file serves as an official communication to users and plugin developers, providing guidance on usage changes, new APIs, and upgrade considerations.

The release focuses on enhancing test parametrization, marker handling, and profiling test durations, along with improved teardown behavior for more accurate reporting.


Detailed Description

Purpose and Functionality

The document’s primary purpose is to:

This file is typically distributed with the pytest package and referenced by developers during upgrades or when exploring new functionalities.


Key Features Introduced

  1. Test Parametrization Enhancements

    • @pytest.mark.parametrize Decorator
      Allows test functions to be run multiple times with different argument sets. This makes it easier to write data-driven tests.

    • metafunc.parametrize() API
      A more flexible, programmatic interface to parametrize tests from plugins or hooks, enabling independent parameter injection.

    Example usage of `@pytest.mark.parametrize`:

    import pytest
    
    @pytest.mark.parametrize("input,expected", [
        (1, 2),
        (3, 4),
        (5, 6),
    ])
    def test_increment(input, expected):
        assert input + 1 == expected
    

    More examples and detailed usage are available at: http://pytest.org/en/stable/example/how-to/parametrize.html

  2. Improved Test Markers and Selection

    • New -m markexpr command-line option to select tests by their markers. This provides a stricter alternative to the -k option.

    • A markers ini configuration variable to register known markers for the project, helping avoid typos.

    • A --strict option that causes pytest to error out if unregistered markers are used, enforcing marker discipline.

    For usage examples, visit: http://pytest.org/en/stable/example/markers.html

  3. Duration Profiling

    • The --duration=N command-line option reports the N slowest test calls, including setup and teardown phases, helping identify performance bottlenecks in tests.

  4. Eager Teardown Execution

    • Teardown and finalizer functions are now called more eagerly, improving the accuracy of failure reporting related to cleanup code.


Compatibility and Upgrade Notes


Bug Fixes and Miscellaneous Improvements


Implementation Details


Interactions with Other System Components


Mermaid Diagram: Structural Overview of release-2.2.0.rst

The file is a textual changelog and does not define classes or functions but documents several key features and CLI options. The diagram below illustrates the main features and their relationships as described in the release.

flowchart TD
    A[pytest 2.2.0 Release] --> B[Parametrization]
    A --> C[Test Markers]
    A --> D[Duration Profiling]
    A --> E[Eager Teardown]
    B --> B1[@pytest.mark.parametrize decorator]
    B --> B2[metafunc.parametrize() API]
    C --> C1[-m markexpr option]
    C --> C2[markers ini-variable]
    C --> C3[--strict option]
    D --> D1[--duration=N option]
    E --> E1[Earlier teardown/finalizer calls]
    B1 -->|Usage| F[Multiple test runs with varied inputs]
    C1 -->|Usage| G[Select tests by marker]
    C3 -->|Enforcement| H[Error on unregistered markers]

Summary

`release-2.2.0.rst` is a comprehensive release note file for pytest 2.2.0, detailing major new features—primarily around test parametrization, marker handling, and profiling—along with compatibility notes and bug fixes. It serves as an essential resource for users upgrading pytest or developing plugins, helping them understand new capabilities and required changes. The file directs users to extensive online examples and documentation, reinforcing best practices for test development and execution with the new release.


**End of documentation.**