release-2.2.2.rst

Overview

This file is a release note document for **pytest version 2.2.2**, a minor backward-compatible update of the popular Python testing tool [py.test](/projects/286/67543). It summarizes the purpose of the release, installation instructions, acknowledgments to contributors, and a detailed list of bug fixes and refinements that were introduced since the previous version (2.2.1). The release specifically improves test reporting (especially with the `--collectonly` option), fixes bugs related to test parametrization, finalization, monkeypatching, and enhances error messages.

The document serves as a historical changelog and guidance for users upgrading or installing pytest, enabling them to understand what issues have been resolved and what new behaviors or fixes to expect.


Detailed Content Description

Release Information

Installation Instructions

Users can install or upgrade pytest using standard Python package management commands:

pip install -U pytest

or

easy_install -U pytest

Acknowledgments

Special thanks are given to contributors Ronny Pfannschmidt, Ralf Schmitt, and others who helped resolve issues reported for this release.


Bug Fixes and Improvements Between 2.2.1 and 2.2.2

The release note enumerates specific issues addressed and features improved:

Issue/Feature

Description

**issue101**

Fixes wrong arguments passed to `unittest.TestCase` test functions, improving output clarity.

**issue102**

Improves error reporting when test directories are renamed but leftover `.pyc` or `__pycache__` files remain.

**issue106**

Allows the `parametrize` decorator to be applied multiple times across module, class, and function levels.

**issue107**

Ensures the session scope finalization is actually performed as expected.

**Parametrize indirect check**

Prevents checking `parametrize` when indirect parameters are function argument names (funcarg names).

**Monkeypatch additions**

Adds a `chdir` method to the monkeypatch fixture for changing directories; fixes crash on multiple `undo` calls.

**issue115**

Makes `--collectonly` option robust to early failures such as missing files or directories.

**Quiet collectonly output**

`-qq --collectonly` now displays only file names and test counts; `-q --collectonly` shows test IDs.

**Distributed testing**

Enhances test report attribute addition compatibility with distributed testing without requiring pytest-xdist upgrades.


Implementation Details and Algorithms

This file is a plain text reStructuredText (`.rst`) changelog and does not contain implementation code, classes, or functions. Instead, it documents fixes in the underlying pytest codebase. Some notable implementation aspects inferred:


Interaction with Other System Components


Usage Examples

Although the release note itself does not provide code snippets, here are illustrative examples based on the fixes described:

**Using multiple parametrize decorators:**

import pytest

@pytest.mark.parametrize('x', [1, 2])
@pytest.mark.parametrize('y', [3, 4])
def test_multiparam(x, y):
    assert x + y > 0

**Using monkeypatch's new `chdir` method:**

def test_change_directory(monkeypatch):
    monkeypatch.chdir('/tmp')
    import os
    assert os.getcwd() == '/tmp'
    # After test, monkeypatch.undo() will restore original directory

**Running pytest with improved collectonly reporting:**

pytest -qq --collectonly
# Output: shows file names and number of tests only

pytest -q --collectonly
# Output: shows test IDs

Mermaid Diagram: Structure of release-2.2.2.rst

Since this file is a changelog documenting a set of issues and fixes, the most suitable visualization is a **flowchart** depicting the main topics covered and their relations:

flowchart TD
    A[release-2.2.2.rst] --> B[Overview]
    A --> C[Installation Instructions]
    A --> D[Acknowledgments]
    A --> E[Bug Fixes and Improvements]
    E --> E1[Fix issue101: unittest args]
    E --> E2[Fix issue102: dir rename errors]
    E --> E3[Fix issue106: multiple parametrize]
    E --> E4[Fix issue107: session finalization]
    E --> E5[Monkeypatch: chdir & undo fix]
    E --> E6[Fix issue115: robust collectonly]
    E --> E7[Collectonly quiet modes]
    E --> E8[Distributed testing attribute fix]

Summary

The `release-2.2.2.rst` file is a concise yet comprehensive release note for pytest version 2.2.2. It informs users about important bug fixes and enhancements related to test parametrization, monkeypatching, reporting, and distributed testing compatibility. While the file does not contain executable code, it provides valuable context and guidance for developers and testers working with pytest, ensuring smooth upgrades and better test outcomes.

This documentation helps maintain clarity on the evolution of pytest and supports effective use of its features in testing workflows.