release-2.6.1.rst

Overview

This file contains the release notes and changelog for the pytest testing framework version 2.6.1. Pytest is a widely used Python testing tool that simplifies writing and running tests. The 2.6.1 release is a patch update focused on fixing regressions introduced in version 2.6.0 while maintaining compatibility with version 2.5.2. Additionally, it introduces an enhancement to the `xfail` marker, allowing specification of expected exceptions.

The document serves as a concise summary of fixes, improvements, and acknowledgments for contributors involved in this release.

Purpose and Functionality

Detailed Content Breakdown

Release Description

Upgrade Instructions

Users can upgrade to this version via the Python Package Index (PyPI) using the command:

pip install -U pytest

Notable Contributors

Change Log Summary

Fix / Feature

Description

Contributor

Remove line numbers in verbose output

The `--verbose` output no longer shows line numbers, only node IDs; line numbers remain in failure reports.

Floris Bruynooghe

Assertion rewriting fix

Fixed issue #437 where pytest-xdist worker nodes collected different tests due to assertion rewriting.

Bruno Oliveira

Add `errors` attribute to capture streams

Added `errors` attribute to captured streams (`sys.stdout.errors`) to improve compatibility.

Bruno Oliveira

Fix output capturing with capsys/capfd

Ensured that `capsys` and `capfd` fixtures work even when output capturing (`-s`) is disabled.

`xfail` expected exceptions enhancement

Allowed `pytest.mark.xfail` to accept `raises=EXC` argument to specify expected exceptions.

David Mohr

Integration fix with `unittest.mock.patch`

Fixed interaction with `mock.patch` decorator when using the `new` argument.

Nicolas Delaby

Conftest detection fix

Fixed detection of `conftest.py` files when test node IDs contain `::` specifications.

Fix `@NUM` removal logic

Restricts removal of `@NUM` suffixes to only parts with `.py` extensions in node IDs.

Removed py.std import helper

Direct imports used instead of `py.std` import helper for better clarity and maintenance.

Bruno Oliveira

Important Implementation Details

Interaction with Other System Components

Usage Examples

Using the new raises argument with xfail

You can mark a test as an expected failure only if it raises a specific exception:

import pytest

@pytest.mark.xfail(raises=ValueError)
def test_divide():
    assert 1 / 0  # This raises ZeroDivisionError, so test will be reported as failure, not xfail

@pytest.mark.xfail(raises=(ZeroDivisionError, ValueError))
def test_divide_multiple():
    assert 1 / 0  # This raises ZeroDivisionError, considered expected, reported as xfail

This feature helps distinguish between failures caused by expected exceptions and other unexpected errors.

Visual Diagram

The following Mermaid class diagram summarizes the key conceptual entities and relationships implied in this release notes file, focusing on pytest testing constructs affected:

classDiagram
    class pytest {
        +install()
        +run_tests()
        +mark_xfail(raises=Exception or tuple)
    }

    class TestNode {
        +nodeid: str
        +collect()
        +execute()
    }

    class CaptureStreams {
        +stdout
        +stderr
        +errors
    }

    class pystd_import_helper {
        <<deprecated>>
    }

    pytest --> TestNode : manages
    pytest --> CaptureStreams : captures output
    pytest ..|> pystd_import_helper : replaced by direct imports

Explanation:

Summary

This file is a release notes document for pytest 2.6.1, summarizing bug fixes, minor feature additions (notably the enhanced `xfail` marker), and credits to contributors. It provides users with upgrade instructions, compatibility assurances, and a detailed changelog describing improvements in test collection, output capturing, and test marking. The fixes ensure improved stability and usability of pytest, especially in distributed and complex testing scenarios.


For more information, users are referred to the official pytest documentation: http://pytest.org