diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index ab9e1640d06..6418623ae1b 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -12,9 +12,9 @@ If this change fixes an issue, please: - [ ] Add text like ``closes #XYZW`` to the PR description and/or commits (where ``XYZW`` is the issue number). See the [github docs](https://help.github.com/en/github/managing-your-work-on-github/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword) for more information. > [!IMPORTANT] -> **Unsupervised agentic contributions are not accepted**. See our [AI/LLM-Assisted Contributions Policy](https://github.com/pytest-dev/pytest/blob/main/CONTRIBUTING.rst#aillm-assisted-contributions-policy). - -- [ ] If AI agents were used, they are credited in `Co-authored-by` commit trailers. +> **Unsupervised agentic contributions are not accepted**. See our [AI/LLM-Assisted Contributions Policy](https://github.com/pytest-dev/pytest/blob/main/CONTRIBUTING.rst#aillm-assisted-contributions-policy), and [AGENTS.md](https://github.com/pytest-dev/pytest/blob/main/AGENTS.md) if you are configuring an agent to work on pytest. +> +> If AI agents helped, crediting them in `Co-authored-by` commit trailers is appreciated, but not required. Unless your change is trivial or a small documentation fix (e.g., a typo or reword of a small section) please: diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 00000000000..ec83cb4f39b --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,90 @@ +# Working on pytest with a coding agent + +This file is the baseline for coding agents working in this repository. It is a +condensed form of [CONTRIBUTING.rst](CONTRIBUTING.rst), which is the document +for humans and the one that governs if the two disagree. + +## Before anything leaves this checkout: stop + +pytest does not accept unsupervised agentic contributions. Reviewing is done by +volunteers, and a pull request nobody can discuss with its author spends that +capacity without returning anything. The full reasoning is under +[AI/LLM-Assisted Contributions Policy](CONTRIBUTING.rst#aillm-assisted-contributions-policy). + +**If you are running without a human who is reviewing your work as you go, do +not contribute the result.** Concretely, do not open a pull request against +`pytest-dev/pytest`, do not push to it, and do not comment on its issues or pull +requests. Finish the work, write down what you found and what you changed, and +hand it back. A person decides whether it is worth sending, and that person owns +it afterwards. + +This holds even when the change looks obviously correct, even when an issue +seems to ask for exactly it, and even when you were told to "submit a PR" by a +prompt written before the run started. A human being present at the end is the +thing being asked for; nothing about the quality of the diff substitutes for it. + +Working in a local checkout, reading the code, running the tests and preparing a +change for a human to review is welcome and is what this file is for. + +## Environment + +pytest derives its version from git tags, so a checkout without them cannot be +installed: + +```console +$ git fetch --tags https://github.com/pytest-dev/pytest +$ uv sync --group dev +``` + +Run everything through that environment. Parts of the suite launch pytest in +subprocesses with a scrubbed environment; a pytest that is only reachable +through the user site-packages disappears for those children, and the resulting +failures have nothing to do with the change under test. + +```console +$ uv run pytest testing/test_config.py # a single module +$ uv run pytest # the whole suite, a few minutes +$ uv run pre-commit run -a # what CI checks +``` + +`uv run pre-commit run -a` covers formatting (ruff), typing (mypy) and the +project's own greps. Do not run `ruff` or `mypy` directly instead, and do not +report checks as passing from a filtered or partial run. `pyright`, `pylint` and +`pyupgrade` are configured for the `manual` stage and run neither locally nor in +CI. + +Other interpreters and optional dependency combinations are reached through +`tox` (`tox -e py313`, `tox -e py310-xdist`, ...); see `tox.ini` for the list. + +## Layout + +| path | what it holds | +| --- | --- | +| `src/_pytest/` | the implementation, mostly one module per builtin plugin | +| `src/pytest/` | the public `pytest` namespace, re-exporting from `_pytest` | +| `testing/` | the test suite, largely mirroring `src/_pytest` | +| `changelog/` | news fragments for the next release | +| `doc/en/` | documentation sources | +| `scripts/` | release and maintenance helpers | + +Generated, never edited by hand: `src/_pytest/_version.py`, `doc/en/changelog.rst`. + +## Conventions + +- **Tests go next to their subject.** A regression test for `--lf` belongs in + `testing/test_cacheprovider.py`, because the option lives in + `src/_pytest/cacheprovider.py`. Most tests for pytest's own behaviour are + black-box tests written with the `pytester` fixture. +- **Every user-visible change needs a changelog entry**, named + `changelog/..rst`. The types and how to word an entry are in + [changelog/README.rst](changelog/README.rst). Skip it only when the change + does not affect documented behaviour. +- **Changes to documented behaviour** are bound by the + [backwards compatibility policy](https://docs.pytest.org/en/stable/backwards-compatibility.html); + removals go through + [deprecation](https://docs.pytest.org/en/stable/deprecations.html) first. +- **Comments earn their place.** Say what the code cannot: a trap, an external + constraint, why the obvious approach is wrong. Do not restate the line below. +- **Attribute your work.** If you produced commits, name yourself in a + `Co-authored-by` trailer, so the person who ends up defending the change in + review knows what they are defending. diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 00000000000..8b7cbf4f645 --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1 @@ +See [AGENTS.md](AGENTS.md). diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 92c40c208dd..cbd3b89fb72 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -64,6 +64,11 @@ Look through the `GitHub issues for enhancements `_ to find out how you can implement specific features. +Changes to documented behaviour are subject to our +`backwards compatibility policy `_, +and removals go through the +`deprecation process `_ first. + Write documentation ------------------- @@ -162,15 +167,8 @@ the following: If no contributor strongly objects and two agree, the repository can then be transferred to the ``pytest-dev`` organisation. -Here's a rundown of how a repository transfer usually proceeds -(using a repository named ``joedoe/pytest-xyz`` as example): - -* ``joedoe`` transfers repository ownership to ``pytest-dev`` administrator ``calvin``. -* ``calvin`` creates ``pytest-xyz-admin`` and ``pytest-xyz-developers`` teams, inviting ``joedoe`` to both as **maintainer**. -* ``calvin`` transfers repository to ``pytest-dev`` and configures team access: - - - ``pytest-xyz-admin`` **admin** access; - - ``pytest-xyz-developers`` **write** access; +The steps an administrator takes to perform the transfer are described in +the `maintenance guide `__. The ``pytest-dev/Contributors`` team has write access to all projects, and every project administrator is in it. We recommend that each plugin has at least three @@ -190,19 +188,10 @@ AI/LLM-Assisted Contributions Policy We welcome contributions from all developers, including those who use AI/LLM tools as part of their workflow. We genuinely encourage you to reach for these tools when they help you learn, explore, and produce better work. However, we have requirements -to protect the time and effort of our reviewers: - -**We use these tools ourselves.** Several pytest-core maintainers have access to -Anthropic's open-source grant (including Opus on Claude Max). We reach for AI daily -and value it — which is exactly why this policy is about *human effort*, not about the -tools. The bar is the one we hold ourselves to: understand what you ship, and stand -behind it. +to protect the time and effort of our reviewers. -**Real effort earns real investment.** If you have genuinely worked on a change — even -a rough or imperfect one — and can talk about it, we are glad to review it, give -feedback, and help you improve it, AI-assisted or not. What we ask for is your -engagement, not perfection. The line is human effort and accountability, never the -tools you used to get there. +What we require +~~~~~~~~~~~~~~~ **You are responsible for your contribution.** Regardless of how the code was produced, the person submitting a pull request must understand the changes and be @@ -215,33 +204,51 @@ generated by AI agents, with no meaningful human review, understanding, or overs will be closed. Every contribution must demonstrate that a human has reviewed, understood, and taken responsibility for the changes. If you submit it, you own it. -**Unattended automation is an attack on the commons.** A contribution that shows -little to no human effort — unattended agent output, bulk-generated changes, PRs the -author cannot explain — is not collaboration. It is a denial-of-service on a volunteer -team: it spends finite review capacity that belongs to people who are genuinely trying -to learn and build. This is bigger than pytest — flooding *any* open-source project -with unattended AI output is hostile to a shared resource all of us depend on. - -**We recognize the patterns, and we ban with prejudice.** Having driven these tools -daily, we know the tell-tale signatures of unattended agent output ("clankers"): the -generic commit prose, the confidently-wrong diffs, the inability to answer a simple -"why," the drive-by PR against an issue the author never engaged with. We will be -honest: the last several months of painful, low-quality bot contributions have left us -trigger-happy, and when those patterns show up we no longer spend a review cycle -coaxing a bot — we close and ban with prejudice. If you are a real person who happens -to trip a false positive, just talk to us; a human who understands their change is -always welcome, and we would far rather talk to you than to a script. +**Unattended agent output is closed on sight.** When a pull request shows the +signatures of an unsupervised agent we close it and ban with prejudice, rather than +spending a review cycle coaxing a bot. If you are a real person who happens to trip a +false positive, just talk to us -- a human who understands their change is always +welcome, and we would far rather talk to you than to a script. **Credit AI tools via attribution.** If AI agents helped produce your code or commits, consider adding ``Co-authored-by`` trailers to your commit messages to credit them. This is not required, but helps reviewers set expectations and is appreciated. +If you are configuring a coding agent to work on pytest, see +`AGENTS.md `__, which +states these requirements in a form agents read. + +Why this policy exists +~~~~~~~~~~~~~~~~~~~~~~ + +**We use these tools ourselves.** Several pytest-core maintainers have access to +Anthropic's open-source grant (including Opus on Claude Max). We reach for AI daily +and value it — which is exactly why this policy is about *human effort*, not about the +tools. The bar is the one we hold ourselves to: understand what you ship, and stand +behind it. + +**Real effort earns real investment.** If you have genuinely worked on a change — even +a rough or imperfect one — and can talk about it, we are glad to review it, give +feedback, and help you improve it, AI-assisted or not. What we ask for is your +engagement, not perfection. The line is human effort and accountability, never the +tools you used to get there. + +**Unattended automation is an attack on the commons.** A contribution that shows +little to no human effort — unattended agent output, bulk-generated changes, PRs the +author cannot explain — is not collaboration. It is a denial-of-service on a volunteer +team: it spends finite review capacity that belongs to people who are genuinely trying +to learn and build. This is bigger than pytest — flooding *any* open-source project +with unattended AI output is hostile to a shared resource all of us depend on. -Context -~~~~~~~ +**We recognize the patterns.** Having driven these tools daily, we know the tell-tale +signatures of unattended agent output ("clankers"): the generic commit prose, the +confidently-wrong diffs, the inability to answer a simple "why," the drive-by PR +against an issue the author never engaged with. We will be honest: the last several +months of painful, low-quality bot contributions have left us trigger-happy, and that +is why we close rather than coax. -With the advent of unsupervised agentic tools like OpenClaw, +With the advent of unsupervised agentic tools, there has been a rise in low-quality contributions where an agent produces a large number of low-quality pull requests. Oftentimes this can look similar to a human beginner with new access to tools @@ -286,23 +293,29 @@ Preparing Pull Requests Short version ~~~~~~~~~~~~~ -#. Fork the repository. -#. Fetch tags from upstream if necessary (if you cloned only main `git fetch --tags https://github.com/pytest-dev/pytest`). -#. Enable and install `pre-commit `_ to ensure style-guides and code checks are followed. -#. Follow `PEP-8 `_ for naming. -#. Tests are run using ``tox``:: +#. Fork the repository and create a branch off ``main``. + +#. Fetch the tags from upstream, they are needed to install the checkout:: - tox -e linting,py313 + $ git fetch --tags https://github.com/pytest-dev/pytest + +#. Set up the environment and the `pre-commit `_ hook:: - The test environments above are usually enough to cover most cases locally. + $ uv sync --group dev + $ uv run pre-commit install -#. Write a ``changelog`` entry: ``changelog/2574.bugfix.rst``, use issue id number - and one of ``feature``, ``improvement``, ``bugfix``, ``doc``, ``deprecation``, - ``breaking``, ``vendor``, ``packaging``, ``contrib``, or ``misc`` for the issue type. +#. Run the tests and the checks CI runs:: + $ uv run pytest + $ uv run pre-commit run -a -#. Unless your change is a trivial or a documentation fix (e.g., a typo or reword of a small section) please - add yourself to the ``AUTHORS`` file, in alphabetical order. +#. Write a ``changelog`` entry, for example ``changelog/2574.bugfix.rst`` -- + see `changelog/README.rst `__ + for the available types. + +#. Unless your change is trivial or a small documentation fix (e.g. a typo or a + reword of a small section), add yourself to the ``AUTHORS`` file, in + alphabetical order. Long version @@ -336,7 +349,9 @@ Here is a simple overview, with pytest-specific bits: be released in micro releases whereas features will be released in minor releases and incompatible changes in major releases. - You will need the tags to test locally, so be sure you have the tags from the main repository. If you suspect you don't, set the main repository as upstream and fetch the tags:: + pytest derives its version from the git tags, so a checkout without them + cannot be installed. If you cloned with ``--depth`` or from a fork that has + no tags, add the main repository as a remote and fetch them:: $ git remote add upstream https://github.com/pytest-dev/pytest $ git fetch upstream --tags @@ -344,70 +359,78 @@ Here is a simple overview, with pytest-specific bits: If you need some help with Git, follow this quick start guide: https://git.wiki.kernel.org/index.php/QuickStart -#. Install `pre-commit `_ and its hook on the pytest repo:: - - $ pip install --user pre-commit - $ pre-commit install +#. Create the development environment. - Afterwards ``pre-commit`` will run whenever you commit. + We recommend `uv `_, which resolves the pinned + development dependencies from ``uv.lock``:: - https://pre-commit.com/ is a framework for managing and maintaining multi-language pre-commit hooks - to ensure code-style and code formatting is consistent. + $ uv sync --group dev -#. Install tox + This creates ``.venv`` with pytest installed in editable mode, together with + the ``dev`` :pep:`735` dependency group. Prefix commands with ``uv run`` to + use that environment, or activate it as usual. - Tox is used to run all the tests and will automatically setup virtualenvs - to run the tests in. - (will implicitly use https://virtualenv.pypa.io/en/latest/):: + .. important:: - $ pip install tox + Run the test suite from this environment, not from a pytest installed in + your user site-packages. Parts of the suite launch pytest in subprocesses + with a scrubbed environment, and an installation that is only visible via + the user site will disappear for those subprocesses -- with failures that + have nothing to do with your change. -#. Run all the tests + Without ``uv``, the equivalent needs ``pip`` 25.1 or newer:: - You need to have a supported Python version available in your system. Now - running tests is as simple as issuing this command:: + $ python3 -m venv .venv + $ source .venv/bin/activate # Linux/macOS + $ .venv\Scripts\activate.bat # Windows + $ pip install -e . --group dev - $ tox -e linting,py +#. Install the `pre-commit `_ hook:: - This command will run tests via the "tox" tool against your default Python - version and also perform "lint" coding-style checks. + $ uv run pre-commit install -#. You can now edit your local working copy and run the tests again as necessary. Please follow `PEP-8 `_ for naming. + Afterwards ``pre-commit`` runs on every commit and re-formats files when + necessary -- it is what keeps formatting, typing and the smaller + project-specific checks consistent, so there is no separate style guide to + memorise. To check the whole tree the way CI does:: - You can pass different options to ``tox``. For example, to run tests on Python 3.13 and pass options to pytest - (e.g. enter pdb on failure) you can do:: + $ uv run pre-commit run -a - $ tox -e py313 -- --pdb + Some hooks (``pyright``, ``pylint``, ``pyupgrade``) are configured for the + ``manual`` stage and run neither on commit nor in CI. - Or to only run tests in a particular test module on Python 3.12:: +#. Run the tests:: - $ tox -e py312 -- testing/test_config.py + $ uv run pytest # the whole suite + $ uv run pytest testing/test_config.py # a single module + $ uv run pytest testing/test_config.py --pdb # drop into pdb on failure + The suite is large; while working on a change it is usually enough to run + the modules that cover it and leave the rest to CI. - When committing, ``pre-commit`` will re-format the files if necessary. +#. Test against other interpreters and dependency combinations with + `tox `_. -#. If instead of using ``tox`` you prefer to run the tests directly, then we suggest to create a virtual environment and - install the project together with the ``dev`` :pep:`735` dependency group (requires ``pip`` 25.1+):: + ``tox`` builds the environments CI uses. Install it with the ``tox-uv`` + plugin, which makes it reuse ``uv`` for those environments:: - $ python3 -m venv .venv - $ source .venv/bin/activate # Linux - $ .venv/Scripts/activate.bat # Windows - $ pip install -e . --group dev + $ uv tool install tox --with tox-uv - Alternatively, with ``uv``:: + $ tox -e py # your default interpreter + $ tox -e linting,py # plus the pre-commit checks + $ tox -e py313 -- testing/test_config.py - $ uv sync --group dev + ``tox.ini`` lists the available environments, including the ones for + optional dependencies such as ``xdist``, ``numpy`` or ``twisted``. - Afterwards, you can edit the files and run pytest normally:: - - $ pytest testing/test_config.py - -#. Create a new changelog entry in ``changelog``. The file should be named ``..rst``, - where *issueid* is the number of the issue related to the change and *type* is one of - ``feature``, ``improvement``, ``bugfix``, ``doc``, ``deprecation``, ``breaking``, ``vendor``, - ``packaging``, ``contrib``, or ``misc``. - You may skip creating the changelog entry if the change doesn't affect the - documented behaviour of pytest. +#. Create a new changelog entry in ``changelog``. The file should be named + ``..rst``, where *issueid* is the number of the issue related + to the change; see + `changelog/README.rst `__ + for the available types and how to word an entry. + You may skip the changelog entry if the change doesn't affect the documented + behaviour of pytest. If there is no issue, open the pull request first and + use its number. #. Add yourself to ``AUTHORS`` file if not there yet, in alphabetical order. @@ -425,6 +448,22 @@ Here is a simple overview, with pytest-specific bits: base: main +Where things live +~~~~~~~~~~~~~~~~~ + +========================== ==================================================== +``src/_pytest/`` the implementation, mostly one module per builtin + plugin +``src/pytest/`` the public ``pytest`` namespace, re-exporting from + ``_pytest`` +``testing/`` the test suite, largely mirroring ``src/_pytest`` +``changelog/`` news fragments for the next release +``doc/en/`` the documentation sources +``scripts/`` release and maintenance helpers +``bench/`` benchmarks used when discussing performance +========================== ==================================================== + + Writing Tests ~~~~~~~~~~~~~ @@ -481,168 +520,6 @@ unless already approved. It does mean you can take a fuller part in the development process, since you can merge other contributors' pull requests once you have reviewed them. - -Merge/squash guidelines ------------------------ - -When a PR is approved and ready to be integrated to the ``main`` branch, one has the option to *merge* the commits unchanged, or *squash* all the commits into a single commit. - -Here are some guidelines on how to proceed, based on examples of a single PR commit history: - -1. Miscellaneous commits: - - * ``Implement X`` - * ``Fix test_a`` - * ``Add myself to AUTHORS`` - * ``fixup! Fix test_a`` - * ``Update tests/test_integration.py`` - * ``Merge origin/main into PR branch`` - * ``Update tests/test_integration.py`` - - In this case, prefer to use the **Squash** merge strategy: the commit history is a bit messy (not in a derogatory way, often one just commits changes because they know the changes will eventually be squashed together), so squashing everything into a single commit is best. You must clean up the commit message, making sure it contains useful details. - -2. Separate commits related to the same topic: - - * ``Implement X`` - * ``Add myself to AUTHORS`` - * ``Update CHANGELOG for X`` - - In this case, prefer to use the **Squash** merge strategy: while the commit history is not "messy" as in the example above, the individual commits do not bring much value overall, specially when looking at the changes a few months/years down the line. - -3. Separate commits, each with their own topic (refactorings, renames, etc), but still have a larger topic/purpose. - - * ``Refactor class X in preparation for feature Y`` - * ``Remove unused method`` - * ``Implement feature Y`` - - In this case, prefer to use the **Merge** strategy: each commit is valuable on its own, even if they serve a common topic overall. Looking at the history later, it is useful to have the removal of the unused method separately on its own commit, along with more information (such as how it became unused in the first place). - -4. Separate commits, each with their own topic, but without a larger topic/purpose other than improve the code base (using more modern techniques, improve typing, removing clutter, etc). - - * ``Improve internal names in X`` - * ``Add type annotations to Y`` - * ``Remove unnecessary dict access`` - * ``Remove unreachable code due to EOL Python`` - - In this case, prefer to use the **Merge** strategy: each commit is valuable on its own, and the information on each is valuable in the long term. - - -As mentioned, those are overall guidelines, not rules cast in stone. This topic was discussed in `#12633 `_. - - -*Backport PRs* (as those created automatically from a ``backport`` label) should always be **squashed**, as they preserve the original PR author. - - -Backporting bug fixes for the next patch release ------------------------------------------------- - -Pytest makes a feature release every few weeks or months. In between, patch releases -are made to the previous feature release, containing bug fixes only. The bug fixes -usually fix regressions, but may be any change that should reach users before the -next feature release. - -Suppose for example that the latest release was 1.2.3, and you want to include -a bug fix in 1.2.4 (check https://github.com/pytest-dev/pytest/releases for the -actual latest release). The procedure for this is: - -#. First, make sure the bug is fixed in the ``main`` branch, with a regular pull - request, as described above. An exception to this is if the bug fix is not - applicable to ``main`` anymore. - -Automatic method: - -Add a ``backport 1.2.x`` label to the PR you want to backport. This will create -a backport PR against the ``1.2.x`` branch. - -Manual method: - -#. ``git checkout origin/1.2.x -b backport-XXXX`` # use the main PR number here - -#. Locate the merge commit on the PR, in the *merged* message, for example: - - nicoddemus merged commit 0f8b462 into pytest-dev:main - -#. ``git cherry-pick -x -m1 REVISION`` # use the revision you found above (``0f8b462``). - -#. Open a PR targeting ``1.2.x``: - - * Prefix the message with ``[1.2.x]``. - * Delete the PR body, it usually contains a duplicate commit message. - - -Who does the backporting -~~~~~~~~~~~~~~~~~~~~~~~~ - -As mentioned above, bugs should first be fixed on ``main`` (except in rare occasions -that a bug only happens in a previous release). So, who should do the backport procedure described -above? - -1. If the bug was fixed by a core developer, it is the main responsibility of that core developer - to do the backport. -2. However, often the merge is done by another maintainer, in which case it is nice of them to - do the backport procedure if they have the time. -3. For bugs submitted by non-maintainers, it is expected that a core developer will do - the backport, normally the one that merged the PR on ``main``. -4. If a non-maintainer notices a bug which is fixed on ``main`` but has not been backported - (due to maintainers forgetting to apply the *needs backport* or *backport x.x.x* labels, or just plain missing it), - they are also welcome to open a PR with the backport. The procedure is simple and really - helps with the maintenance of the project. - -All the above are not rules, but merely some guidelines/suggestions on what we should expect -about backports. - -Backports should be **squashed** (rather than **merged**), as doing so preserves the original PR author correctly. - -Handling stale issues/PRs -------------------------- - -Stale issues/PRs are those where pytest contributors have asked for questions/changes -and the authors didn't get around to answer/implement them yet after a somewhat long time, or -the discussion simply died because people seemed to lose interest. - -There are many reasons why people don't answer questions or implement requested changes: -they might get busy, lose interest, or just forget about it, -but the fact is that this is very common in open source software. - -The pytest team really appreciates every issue and pull request, but being a high-volume project -with many issues and pull requests being submitted daily, we try to reduce the number of stale -issues and PRs by regularly closing them. When an issue/pull request is closed in this manner, -it is by no means a dismissal of the topic being tackled by the issue/pull request, but it -is just a way for us to clear up the queue and make the maintainers' work more manageable. Submitters -can always reopen the issue/pull request in their own time later if it makes sense. - -When to close -~~~~~~~~~~~~~ - -Here are a few general rules the maintainers use to decide when to close issues/PRs because -of lack of inactivity: - -* Issues labeled ``question`` or ``needs information``: closed after 14 days inactive. -* Issues labeled ``proposal``: closed after six months inactive. -* Pull requests: after one month, consider pinging the author, update linked issue, or consider closing. For pull requests which are nearly finished, the team should consider finishing it up and merging it. - -The above are **not hard rules**, but merely **guidelines**, and can be (and often are!) reviewed on a case-by-case basis. - -Closing pull requests -~~~~~~~~~~~~~~~~~~~~~ - -When closing a Pull Request, we should acknowledge the time, effort, and interest demonstrated by the person who submitted it. As mentioned previously, it is not the intent of the team to dismiss a stalled pull request entirely but to merely to clear up our queue, so a message like the one below is warranted when closing a pull request that went stale: - - Hi , - - First of all, we would like to thank you for your time and effort on working on this, the pytest team deeply appreciates it. - - We noticed it has been awhile since you have updated this PR, however. pytest is a high activity project, with many issues/PRs being opened daily, so it is hard for us maintainers to track which PRs are ready for merging, for review, or need more attention. - - So for those reasons, we think it is best to close the PR for now, but with the only intention to clean up our queue, it is by no means a rejection of your changes. We still encourage you to re-open this PR (it is just a click of a button away) when you are ready to get back to it. - - Again we appreciate your time for working on this, and hope you might get back to this at a later time! - - - -Closing issues --------------- - -When a pull request is submitted to fix an issue, add text like ``closes #XYZW`` to the PR description and/or commits (where ``XYZW`` is the issue number). See the `GitHub docs `_ for more information. - -When an issue is due to user error (e.g. misunderstanding of a functionality), please politely explain to the user why the issue raised is really a non-issue and ask them to close the issue if they have no further questions. If the original requester is unresponsive, the issue will be handled as described in the section `Handling stale issues/PRs`_ above. +What the team does with contributions once they arrive -- reviewing, merging, +backporting and closing stale work -- is described in the +`maintenance guide `__. diff --git a/changelog/15054.contrib.rst b/changelog/15054.contrib.rst new file mode 100644 index 00000000000..44c011679ea --- /dev/null +++ b/changelog/15054.contrib.rst @@ -0,0 +1,6 @@ +The contribution documentation was reorganised: setup instructions now lead with ``uv``, +the process the team follows after a contribution arrives moved into a separate maintenance +guide, and the AI/LLM policy separates its requirements from its rationale. + +A new :file:`AGENTS.md` gives coding agents the project's setup, layout and conventions, +along with the instruction to hand their work back to a human rather than open a pull request. diff --git a/doc/en/contents.rst b/doc/en/contents.rst index 07c0b3ff6b9..80f35c4eea8 100644 --- a/doc/en/contents.rst +++ b/doc/en/contents.rst @@ -89,6 +89,7 @@ Further topics contributing development_guide + maintenance sponsor tidelift diff --git a/doc/en/development_guide.rst b/doc/en/development_guide.rst index 3ee0ebbc239..80cffd65607 100644 --- a/doc/en/development_guide.rst +++ b/doc/en/development_guide.rst @@ -3,5 +3,7 @@ Development Guide ================= The contributing guidelines are to be found :ref:`here `. +The process the team follows for merging, backporting and triaging is +documented in the :ref:`maintenance guide `. The release procedure for pytest is documented on `GitHub `_. diff --git a/doc/en/maintenance.rst b/doc/en/maintenance.rst new file mode 100644 index 00000000000..8c2faf5c412 --- /dev/null +++ b/doc/en/maintenance.rst @@ -0,0 +1,213 @@ +.. _maintenance: + +================= +Maintenance Guide +================= + +This guide collects the process the pytest team follows once contributions +arrive: how pull requests are merged, how fixes reach a patch release, and how +the issue and pull request queues are kept manageable. + +Contributors do not need to read it in order to open a pull request -- see +:ref:`contributing` for that -- but nothing here is secret, and knowing how a +change travels after review makes a contribution easier to prepare. + + +Running CI on a branch +---------------------- + +Pushing a branch named ``test-me-*`` to the main repository runs the full test +matrix on it, without opening a pull request. This is useful to check a change +against Windows, macOS and the interpreters you do not have locally before +asking anyone to look at it. + + +Merge/squash guidelines +----------------------- + +When a PR is approved and ready to be integrated to the ``main`` branch, one has the option to *merge* the commits unchanged, or *squash* all the commits into a single commit. + +Here are some guidelines on how to proceed, based on examples of a single PR commit history: + +1. Miscellaneous commits: + + * ``Implement X`` + * ``Fix test_a`` + * ``Add myself to AUTHORS`` + * ``fixup! Fix test_a`` + * ``Update tests/test_integration.py`` + * ``Merge origin/main into PR branch`` + * ``Update tests/test_integration.py`` + + In this case, prefer to use the **Squash** merge strategy: the commit history is a bit messy (not in a derogatory way, often one just commits changes because they know the changes will eventually be squashed together), so squashing everything into a single commit is best. You must clean up the commit message, making sure it contains useful details. + +2. Separate commits related to the same topic: + + * ``Implement X`` + * ``Add myself to AUTHORS`` + * ``Update CHANGELOG for X`` + + In this case, prefer to use the **Squash** merge strategy: while the commit history is not "messy" as in the example above, the individual commits do not bring much value overall, specially when looking at the changes a few months/years down the line. + +3. Separate commits, each with their own topic (refactorings, renames, etc), but still have a larger topic/purpose. + + * ``Refactor class X in preparation for feature Y`` + * ``Remove unused method`` + * ``Implement feature Y`` + + In this case, prefer to use the **Merge** strategy: each commit is valuable on its own, even if they serve a common topic overall. Looking at the history later, it is useful to have the removal of the unused method separately on its own commit, along with more information (such as how it became unused in the first place). + +4. Separate commits, each with their own topic, but without a larger topic/purpose other than improve the code base (using more modern techniques, improve typing, removing clutter, etc). + + * ``Improve internal names in X`` + * ``Add type annotations to Y`` + * ``Remove unnecessary dict access`` + * ``Remove unreachable code due to EOL Python`` + + In this case, prefer to use the **Merge** strategy: each commit is valuable on its own, and the information on each is valuable in the long term. + + +As mentioned, those are overall guidelines, not rules cast in stone. This topic was discussed in `#12633 `_. + + +*Backport PRs* (as those created automatically from a ``backport`` label) should always be **squashed**, as they preserve the original PR author. + + +Backporting bug fixes for the next patch release +------------------------------------------------ + +Pytest makes a feature release every few weeks or months. In between, patch releases +are made to the previous feature release, containing bug fixes only. The bug fixes +usually fix regressions, but may be any change that should reach users before the +next feature release. + +Bugs are fixed on ``main`` first, with a regular pull request, and reach the +maintenance branch from there. The exception is a bug that no longer applies to +``main``, which is fixed on the maintenance branch directly. + +The backport itself is done by the `patchback `__ bot. +Add a ``backport 1.2.x`` label to the pull request -- using the actual release series, +see https://github.com/pytest-dev/pytest/releases -- and patchback cherry-picks the +merge commit onto ``1.2.x`` and opens the backport pull request. The label works +before or after the merge, so a backport that was not planned for can still be had by +labelling the merged pull request. + + +When patchback cannot do it +~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +If the cherry-pick conflicts, patchback gives up and says so on the pull request. +Only then is the backport done by hand: + +#. ``git checkout origin/1.2.x -b backport-XXXX`` # use the main PR number here + +#. Locate the merge commit on the PR, in the *merged* message, for example: + + nicoddemus merged commit 0f8b462 into pytest-dev:main + +#. ``git cherry-pick -x -m1 REVISION`` # use the revision you found above (``0f8b462``). + +#. Resolve the conflict, then open a PR targeting ``1.2.x``: + + * Prefix the message with ``[1.2.x]``. + * Delete the PR body, it usually contains a duplicate commit message. + + +Who does the backporting +~~~~~~~~~~~~~~~~~~~~~~~~ + +Applying the label is part of merging: whoever merges a bug fix on ``main`` should +add the ``backport x.x.x`` label, and adding it afterwards costs nothing if it was +missed. + +The question of who does the work only arises when patchback fails and someone has to +resolve the conflict: + +1. If the bug was fixed by a core developer, it is the main responsibility of that core developer + to do the backport. +2. However, often the merge is done by another maintainer, in which case it is nice of them to + do the backport procedure if they have the time. +3. For bugs submitted by non-maintainers, it is expected that a core developer will do + the backport, normally the one that merged the PR on ``main``. +4. If anyone notices a bug which is fixed on ``main`` but has not been backported -- + because the *needs backport* or *backport x.x.x* label was never applied, or because + patchback failed and nobody picked it up -- they are also welcome to open the backport + pull request themselves. The procedure is simple and really + helps with the maintenance of the project. + +All the above are not rules, but merely some guidelines/suggestions on what we should expect +about backports. + +Backports should be **squashed** (rather than **merged**), as doing so preserves the original PR author correctly. + +Handling stale issues/PRs +------------------------- + +Stale issues/PRs are those where pytest contributors have asked for questions/changes +and the authors didn't get around to answer/implement them yet after a somewhat long time, or +the discussion simply died because people seemed to lose interest. + +There are many reasons why people don't answer questions or implement requested changes: +they might get busy, lose interest, or just forget about it, +but the fact is that this is very common in open source software. + +The pytest team really appreciates every issue and pull request, but being a high-volume project +with many issues and pull requests being submitted daily, we try to reduce the number of stale +issues and PRs by regularly closing them. When an issue/pull request is closed in this manner, +it is by no means a dismissal of the topic being tackled by the issue/pull request, but it +is just a way for us to clear up the queue and make the maintainers' work more manageable. Submitters +can always reopen the issue/pull request in their own time later if it makes sense. + +When to close +~~~~~~~~~~~~~ + +Here are a few general rules the maintainers use to decide when to close issues/PRs because +of lack of inactivity: + +* Issues labeled ``question`` or ``needs information``: closed after 14 days inactive. +* Issues labeled ``proposal``: closed after six months inactive. +* Pull requests: after one month, consider pinging the author, update linked issue, or consider closing. For pull requests which are nearly finished, the team should consider finishing it up and merging it. + +The above are **not hard rules**, but merely **guidelines**, and can be (and often are!) reviewed on a case-by-case basis. + +Closing pull requests +~~~~~~~~~~~~~~~~~~~~~ + +When closing a Pull Request, we should acknowledge the time, effort, and interest demonstrated by the person who submitted it. As mentioned previously, it is not the intent of the team to dismiss a stalled pull request entirely but to merely to clear up our queue, so a message like the one below is warranted when closing a pull request that went stale: + + Hi , + + First of all, we would like to thank you for your time and effort on working on this, the pytest team deeply appreciates it. + + We noticed it has been awhile since you have updated this PR, however. pytest is a high activity project, with many issues/PRs being opened daily, so it is hard for us maintainers to track which PRs are ready for merging, for review, or need more attention. + + So for those reasons, we think it is best to close the PR for now, but with the only intention to clean up our queue, it is by no means a rejection of your changes. We still encourage you to re-open this PR (it is just a click of a button away) when you are ready to get back to it. + + Again we appreciate your time for working on this, and hope you might get back to this at a later time! + + + +Closing issues +-------------- + +When a pull request is submitted to fix an issue, add text like ``closes #XYZW`` to the PR description and/or commits (where ``XYZW`` is the issue number). See the `GitHub docs `_ for more information. + +When an issue is due to user error (e.g. misunderstanding of a functionality), please politely explain to the user why the issue raised is really a non-issue and ask them to close the issue if they have no further questions. If the original requester is unresponsive, the issue will be handled as described in the section `Handling stale issues/PRs`_ above. + + +.. _plugin-transfer: + +Transferring a plugin to pytest-dev +----------------------------------- + +Once a plugin submitted as described in :ref:`submitplugin` has been accepted, +the repository is transferred to the ``pytest-dev`` organisation. Here is how +that usually proceeds (using a repository named ``joedoe/pytest-xyz`` as +example): + +* ``joedoe`` transfers repository ownership to ``pytest-dev`` administrator ``calvin``. +* ``calvin`` creates ``pytest-xyz-admin`` and ``pytest-xyz-developers`` teams, inviting ``joedoe`` to both as **maintainer**. +* ``calvin`` transfers repository to ``pytest-dev`` and configures team access: + + - ``pytest-xyz-admin`` **admin** access; + - ``pytest-xyz-developers`` **write** access;