release-2.6.0.rst
Overview
This file documents the release notes and key changes introduced in **pytest version 2.6.0**, a mature Python testing framework. The release focuses on improvements in traceback reporting, a new internal warning system, enhanced integration with other testing utilities (nose, mock, unittest), and multiple bug fixes.
The document serves as both an announcement and a detailed changelog, outlining new features, bug fixes, internal improvements, and contributor acknowledgements. It is intended for users upgrading from previous pytest versions (notably 2.5.2) and for developers interested in the evolution of pytest’s core functionality.
Key highlights of this release include:
Shorter and clearer tracebacks by default.
A new warning system reporting oddities during test collection and execution.
Enhanced compatibility with mocking and unittest frameworks.
Numerous bug fixes improving stability and usability.
Detailed Documentation
New Features and Changes
Shorter Tracebacks by Default
Purpose: Improve readability of test failure tracebacks by showing only the initial test function entry and the final failure location in full detail.
Functionality: Intermediate traceback entries are shown in a “short” format by default.
Usage: Users can revert to the old verbose behavior with the CLI option
--tb=long. The new default option is--tb=auto.Benefit: Makes it easier to quickly identify the root cause of test failures, reducing noise from irrelevant stack frames.
New Warning System
Purpose: Provide enhanced diagnostics during test collection and execution.
Functionality: Detects oddities such as ignoring certain test classes (e.g., those with
__init__methods) and callable test-like objects that are not functions.Implementation: Warnings are routed to the
pytest_logwarninghook, implemented by the terminal plugin to display warnings in the summary line and with detailed-rwreports.Impact: Helps users identify potential issues early, improving test suite reliability.
Integration Enhancements
Improved support for nose, mock, and unittest frameworks.
Fixes related to handling of mock’s double-patching behavior.
Support for nose-style test attribute to control test collection.
Bug Fixes and Improvements
Avoid importing deprecated assertion reinterpretation code by default.
Enhance assertion handling for private class attributes.
Output full node IDs in verbose mode to allow targeted test runs.
Early failure on incorrect pytest.raises usage.
Improved fixture finalizer behavior on failures.
Better handling of stdout/stderr FDs to avoid crashes.
Leak fixes in pytest’s own test suite.
Various internal cleanups including conftest file handling and exception reference cycle breaking.
Usage Examples
**Running tests with shorter tracebacks (default in 2.6.0):**
pytest tests/
**Running tests with full long tracebacks:**
pytest --tb=long tests/
**Running a single test by node ID (includes file, class, method, line number):**
pytest path/to/test_module.py::TestClass::test_method
**Report warnings in detail:**
pytest -rw tests/
Important Implementation Details
The traceback shortening is implemented by modifying the traceback formatting logic to show only the first and last entries fully, and others in a shortened format.
The warning system is integrated deeply into the pytest collection and execution lifecycle, issuing warnings via hooks rather than raising exceptions, allowing non-disruptive visibility.
Integration with external testing tools is maintained and improved by handling edge cases such as mock’s method patching and unittest’s skip exceptions.
Internal cleanup focuses on robustness against file descriptor changes, improved conftest discovery heuristics, and cycle-breaking in exception management to avoid memory leaks.
Interaction with Other Components
Terminal Plugin: Receives warnings via the
pytest_logwarninghook to display in summaries and detailed reports.Test Collectors: Modified to issue warnings when encountering unusual test collection patterns (e.g., test classes with
__init__).Assertion Rewrite: Disabled deprecated code paths by default to prevent importing old assertion reinterpretation modules.
Fixtures: Finalizer logic improved to ensure invalidation even on failures.
External Tools: Enhanced compatibility and integration with
nose,mock, andunittestframeworks, ensuring pytest can run tests written using those tools seamlessly.
Mermaid Diagram
The file is primarily a changelog and does not define classes or functions directly, but it references core pytest components such as the warning system and traceback formatting. Below is a flowchart representing the major functional areas affected in this release and their interactions.
flowchart TD
A[pytest Test Runner] --> B[Test Collection]
B --> C[Warning System]
B --> D[Traceback Formatter]
C --> E[pytest_logwarning Hook]
E --> F[Terminal Plugin]
D --> F
A --> G[Fixture Finalizers]
G --> H[Invalidation Handling]
A --> I[Integration Modules]
I --> J[nose/unittest Support]
I --> K[mock Support]
style A fill:#f9f,stroke:#333,stroke-width:2px
style C fill:#bbf,stroke:#333
style D fill:#bbf,stroke:#333
style E fill:#bfb,stroke:#333
style F fill:#bfb,stroke:#333
style G fill:#ffb,stroke:#333
style I fill:#fbf,stroke:#333
This diagram shows how the pytest test runner coordinates test collection, which triggers the warning system and traceback formatting, both of which feed information to the terminal plugin for user display. Fixture finalizers and integration modules enhance test lifecycle management and compatibility with other testing frameworks.
**Summary:** This release note file for pytest 2.6.0 comprehensively communicates the new features, bug fixes, and internal improvements to users and developers. It primarily focuses on enhancing test failure readability, introducing a structured internal warning system, and improving compatibility with external test tools—all while maintaining backward compatibility with prior pytest versions.