Pytest Accept banner
max-sixty max-sixty

Pytest Accept

Testing community

Description

A pytest plugin for automatically updating doctest outputs

Installation

This entry records only its repository, not the path inside it, so there is no exact command to give. Open the source below and copy the folder into ~/.claude/skills/, or the file into ~/.claude/agents/.

README

pytest-accept

[![GitHub Workflow CI Status](https://img.shields.io/github/actions/workflow/status/max-sixty/pytest-accept/test.yaml?branch=main&logo=github&style=for-the-badge)](https://github.com/max-sixty/pytest-accept/actions?query=workflow:test) [![PyPI Version](https://img.shields.io/pypi/v/pytest-accept?style=for-the-badge)](https://pypi.python.org/pypi/pytest-accept/) [![GitHub License](https://img.shields.io/github/license/max-sixty/pytest-accept?style=for-the-badge)](https://github.com/max-sixty/pytest-accept/blob/main/LICENSE)

pytest-accept is a pytest plugin for automatically updating outputs. It runs along with pytest, observes the generated outputs, and writes them to the test's documented outputs.

Before

def extract_functions(code):
    return re.findall(r"(\w+)\(", code)


def test_extract_functions():
    assert extract_functions("print('hi')") == ["print"]
    assert extract_functions("sum(map(f, x))") == ["sum"]

After `pytest --accept`

def test_extract_functions():
    assert extract_functions("print('hi')") == ["print"]
-   assert extract_functions("sum(map(f, x))") == ["sum"]
+   assert extract_functions("sum(map(f, x))") == ["sum", "map"]

pytest-accept is decoupled from the tests it works with — it can be used with existing tests, and the tests it edits are no different from normal tests. It works with both doctests and normal `assert` statements.

Installation

uv tool install -U pytest-accept

Or with pip:

pip install pytest-accept

To run, just pass `--accept` to pytest:

pytest --accept

Why?

  • Often it's fairly easy to observe whether something is working by viewing the output it produces
  • ...but often the output is verbose, and copying and pasting the output into the test is tedious
  • pytest-accept does the copying & pasting for you
  • Similarly, lots of folks generally find writing any tests a bit annoying, and prefer to develop by "running the code and