backwards-compatibility.rst
Overview
The **backwards-compatibility.rst** file documents the *Backwards Compatibility Policy* of the pytest testing framework. Its primary purpose is to explain pytest's approach to maintaining backward compatibility across releases, managing API transitions, deprecations, removals, and breaking changes. This document serves as a guideline for users, plugin authors, and contributors to understand how pytest evolves without imposing undue disruption.
This file does not contain executable code but provides a detailed policy, historical context, and version support information critical for maintaining ecosystem stability during pytest's evolution.
Key Topics Covered:
Types of backward compatibility transitions (trivial, transitional, true breakage)
Deprecation and removal strategy with warning mechanisms
Communication and coordination process for breaking changes
Historical stance on backward compatibility pre-6.0
Python version support matrix for different pytest releases
Detailed Explanations
Since this is a policy document without code entities such as classes or functions, the documentation focuses on the conceptual frameworks and processes described within.
Backwards Compatibility Transitions
Pytest considers three main types of transitions when evolving APIs:
Trivial transitions
APIs that can be translated into newer mechanisms without causing issues.
Supported indefinitely.
Users encouraged to migrate via documentation.
Transitional transitions
Old and new APIs coexist without conflict.
Support is maintained with deprecation warnings for an extended period.
Removal happens only in major releases, with at least two minor releases of overlap.
Deprecated features slated for removal in major version X issue
PytestRemovedInXWarningwarnings.Upon release of version X, deprecated features become errors by default before actual removal in the next minor release.
True breakage
Reserved for changes that are unsustainable to transition or affect very few users.
Must be coordinated with the community via detailed issues and proof-of-concept (POC) pull requests.
Includes rationale, impact analysis, and migration instructions.
Followed by deprecation periods and documentation updates before final removal.
Deprecation and Warning Strategy
Deprecations use custom warning classes inheriting from
PytestDeprecationWarning.Warnings can be controlled via standard Python warning filters or pytest's -W flag and filterwarnings ini options.
Removal workflows:
Feature deprecated in version N.
Warning class PytestRemovedIn(N+1)Warning introduced.
At version N+1 release, deprecated features raise errors by default.
At version N+1.x release, features are removed entirely.
History and Philosophy
Pytest prioritizes smooth transitions and long-term backward compatibility.
Deprecations are motivated by simpler or more efficient alternatives.
Clear communication of deprecation timelines started with pytest 3.0.
Use of a custom warning hierarchy for consistent communication.
Deprecation warnings are temporary and intended to be heeded.
Python Version Support
Supported Python versions for pytest releases based on active Python maintenance status at release time:
pytest version | Minimum Python version supported |
|---|---|
8.4+ | 3.9+ |
8.0+ | 3.8+ |
7.1+ | 3.7+ |
6.2 - 7.0 | 3.6+ |
5.0 - 6.1 | 3.5+ |
3.3 - 4.6 | 2.7, 3.4+ |
This table helps users understand compatibility constraints and plan upgrades accordingly.
Implementation Details and Algorithms
Since this file is a documentation policy (reStructuredText) and not a code module, it contains no implementation code, algorithms, or methods.
However, it references critical implementation mechanisms in pytest's codebase:
Custom warning classes for deprecation and removal warnings (
PytestDeprecationWarningandPytestRemovedInXWarningsubclasses).Warning filters to escalate deprecated feature usage to errors.
Use of GitHub labels (
type: deprecation,type: removal) to track deprecation/removal progress.Coordination workflow involving Issues and Pull Requests to manage breaking changes.
Interactions with Other Parts of the System
Warning Subsystem: The policy depends on pytest's internal custom warning classes and Python's standard warnings framework to notify users of deprecated features.
Documentation: References other documentation files like doc/en/deprecations.rst for migration instructions and detailed deprecation explanations.
GitHub Issue and PR Workflow: The policy outlines how breaking changes are coordinated through GitHub issues and pull requests, integrating community feedback and planning.
Plugin Ecosystem: The policy is critical for plugin authors to adapt their plugins according to pytest's evolving APIs and deprecation cycles.
Versioning and Release Process: The removal timeline depends on pytest's semantic versioning and release cadence, tightly coupling deprecation phases to major and minor releases.
Visual Diagram
Below is a **flowchart** representing the *Backwards Compatibility Transition Workflow* described in the document. This diagram illustrates the three transition types and their lifecycle from introduction through deprecation to removal.
flowchart TD
A[Start: New or Modified API] --> B{Type of Transition?}
B -->|Trivial| C[Support indefinitely]
B -->|Transitional| D[Support both old & new APIs]
D --> E[Issue deprecation warning: PytestDeprecationWarning]
E --> F[Deprecated feature scheduled for removal in major release X]
F --> G[Use PytestRemovedInXWarning subclass warning]
G --> H[At release X: warnings become errors by default]
H --> I[At release X.minor: feature removed]
B -->|True Breakage| J[Announce in GitHub issue]
J --> K[Community discussion & impact assessment]
K --> L[POC Pull Request with deprecation warnings]
L --> M[Deprecation period & documentation updates]
M --> N[Merge POC PR for next major release]
N --> I
style C fill:#D5F5E3,stroke:#27AE60,stroke-width:2px
style D fill:#FCF3CF,stroke:#F1C40F,stroke-width:2px
style J fill:#FADBD8,stroke:#E74C3C,stroke-width:2px
Usage Examples
Because this file is a policy document, direct usage examples are not applicable. However, pytest users and plugin authors can expect the following usage scenarios influenced by this policy:
When using deprecated APIs, pytest will emit warnings derived from
PytestDeprecationWarning.Users can suppress or escalate these warnings using Python's -W flag or pytest's filterwarnings ini options.
Plugin authors should monitor pytest's deprecation milestones on GitHub to update their code accordingly.
Upon upgrade to a major pytest version, users may need to fix errors caused by deprecated APIs turned into errors as per the policy's timeline.
Summary
The **backwards-compatibility.rst** file is an essential documentation piece that outlines pytest's philosophy and practices for managing backward compatibility. It ensures that users and developers understand how pytest evolves, how deprecations and removals are handled, and how to plan for transitions effectively, minimizing disruption to testing workflows and plugin ecosystems.
By adhering to this policy, pytest balances innovation and progress with stability and user trust over decades of development.
**End of Documentation**