CONTRIBUTING.rst

Overview

The [CONTRIBUTING.rst](/projects/286/67321) file serves as the official guide for contributing to the *pytest* project. It provides comprehensive instructions and best practices for various contribution activities such as submitting bug reports, feature requests, writing code (including bug fixes and new features), preparing pull requests, writing tests, and joining the development team.

This document aims to ensure a smooth, consistent, and efficient contribution workflow for both new and experienced contributors by outlining the project's expectations, coding standards, and collaboration mechanisms.


Detailed Sections and Usage

This file is structured as a reStructuredText document with multiple thematic sections. Each section focuses on a specific aspect of contributing to pytest.

1. Feature Requests and Feedback


2. Report Bugs


3. Fix Bugs


4. Implement Features


5. Write Documentation

**Docstring Example:**

def my_function(arg: ArgType) -> Foo:
    """Do important stuff.

    :param short_arg: An argument which determines stuff.
    :param long_arg: A long explanation which spans multiple lines.
    :returns: The result.
    :raises ValueError: Detailed info when this can happen.

    .. versionadded:: 6.0
    """

6. Submitting Plugins to pytest-dev


7. Preparing Pull Requests

git clone [email protected]:YOUR_GITHUB_USERNAME/pytest.git
git fetch --tags https://github.com/pytest-dev/pytest
git checkout -b your-branch-name main
pip install --user pre-commit
pre-commit install
pip install tox
tox -e linting,py39
git commit -a -m "Fix issue #123"
git push -u

8. Writing Tests

def test_true_assertion(pytester):
    pytester.makepyfile("def test_foo(): assert True")
    result = pytester.runpytest()
    result.assert_outcomes(passed=1, failed=0)
def test_false_assertion(pytester):
    pytester.makepyfile("def test_foo(): assert False")
    result = pytester.runpytest()
    result.stdout.fnmatch_lines(["*assert False*", "*1 failed*"])

9. Joining the Development Team


10. Merge/Squash Guidelines


11. Backporting Bug Fixes


12. Handling Stale Issues/PRs


13. Closing Issues


Implementation Details


Interactions with Other Parts of the System

The file acts as the centralized resource to align contributors with the project's development standards and workflows, ensuring consistency and quality.


Visual Diagram: Contribution Workflow Flowchart

flowchart TD
    A[Start: Want to contribute?] --> B{Type of Contribution?}
    B -->|Bug Report| C[Submit Issue with Details]
    B -->|Feature Request| D[Submit Issue: Narrow Scope]
    B -->|Code Fix/Feature| E[Fork & Clone Repo]
    E --> F[Create Branch]
    F --> G[Install pre-commit & tox]
    G --> H[Write Code & Tests]
    H --> I[Run Tests with tox]
    I --> J{Tests Pass?}
    J -->|No| H
    J -->|Yes| K[Write Changelog Entry]
    K --> L[Add to AUTHORS if needed]
    L --> M[Commit & Push]
    M --> N[Open Pull Request]
    N --> O{PR Review}
    O -->|Request Changes| H
    O -->|Approved| P[Merge/Squash PR]
    P --> Q[Backport if needed]
    Q --> R[Contribution Complete]
    C & D --> R

Summary

The [CONTRIBUTING.rst](/projects/286/67321) file is an essential guide that standardizes and facilitates contributions to pytest by clearly defining processes for bug reporting, feature requests, coding, testing, documentation, plugin submission, PR preparation, and project maintenance. It supports community engagement and helps maintain the quality and sustainability of the project through well-defined workflows and communication protocols.