pyathy
Test a Python command-line program with scenarios written in plain English.
Quick start
Three commands, in an empty folder:
pipx install pyathy # or: uv tool install pyathy
pyathy init # creates features/hello.feature and a main.py
pyathy # runs it: TOTAL 1 of 1
pyathy init writes this feature:
Feature: Hello World
Scenario: the program greets the world
When I start the program
Then "Hello World" is printed
And the program ends
and this one-line main.py:
print("Hello World")
A first feature
Feature: Tic Tac Toe
Scenario: X wins with the top row
When I input 1, 4, 2, 5, 3
Then "Player X wins!" is printed
And the program asks "Play again? (y/n)"
A Scenario is one run of the program, from a fresh start. When lines act (type answers,
roll dice) and Then lines check what the program did; And continues the line before it.
You write .feature files (Gherkin: Scenario, When, Then) that type answers into
the program, fix its dice rolls, and check what it prints. pyathy runs each scenario against
a fresh start of main.py and shows each run, then one ✔/✘ line per scenario plus a total.
It is built on pytest-bdd and needs Python 3.11+.
Written so that people new to programming can read and write the tests: the steps are the words you would use at the keyboard, and no test code is needed. It tests any Python command-line program, anywhere, the same way.
Ruby has this layer already: Aruba gives Cucumber ready-made steps for command-line programs (run it, type this, expect that output). Python's pytest-bdd has no such layer; pyathy is that layer for Python.
Is pyathy for me?
For developers, what it does and does not do today:
- it tests Python command-line programs, started as a file (
main.py, orthe program other.py) - a package started with
python -mis not supported yet - stdout and stderr are read as one output; no step tells them apart
- no step checks the program's exit status yet
- pyathy itself exits with 1 when a scenario fails, so it fits CI
Install and use
Two ways to get the command. They run the same features the same way.
From PyPI, as a command on your PATH:
pipx install pyathy # or: uv tool install pyathy
or inside a project's venv: pip install pyathy. For VS Code there is the pyathy extension,
MB42.pyathy in the Marketplace.
Poetry, in a Poetry project, as a dev dependency from PyPI:
poetry add --group dev pyathy
poetry run pyathy
Two more ways, both needing a clone of this repo (a no-install pyathy/ folder, and a
venv from the clone), are in docs/install.md.
From the folder that holds main.py and features/ (write python pyathy … for the no-install folder,
poetry run pyathy … under Poetry):
pyathy run every features/*.feature against the program (main.py unless a feature names another)
pyathy features/x.feature run only that file (or folder)
pyathy check find mistakes in the feature files, without running main.py
pyathy init create features/hello.feature (and a main.py) to start from
pyathy steps every step you can use (plus your own, from features/*_steps.py)
pyathy -h usage and an example feature
Options, each with a short and a long form:
-q, --quiet only one line per scenario (a ✘ gets one reason line) and the total
-ff, --fail-fast stop at the first scenario that fails
-nf, --next-failure run the scenarios that failed last time, in order, stopping at the first that still fails
-s, --solution [FOLDER] run the features here against ./_solution/main.py, or ./FOLDER/main.py (-s obj2 means _solution-obj2)
-o, --output show|hide|slow the program's output in the report: show it (the default), hide it, or slow: a line at a time, to read along (on a terminal only)
--delay SECONDS the pause after each line under -o slow (default 0.1: a 100-line run takes 10 seconds; --delay alone means -o slow)
-h, --help this help
-v, --version pyathy's version and where it runs from
The report shows each scenario's run as a terminal would have (what was printed, what was
typed), then its ✔/✘ line with the reason under a ✘, a summary per feature, and the last
line TOTAL n of m; -q keeps only the ✔/✘ lines and the total. Every report ends with
pyathy <version> · <where it runs from>, the same as -v, so two copies on one machine are
never confused. -nf reads the failures remembered in .pyathy/last-run.json; -s runs the
same features against a reference version in _solution/, e.g. to check the features
themselves pass on a known-good version. The report's colours, the long-run cut and the details of -nf and -s: docs/running.md.
pyathy check reads the feature files without running the program and lists, per file,
what would stop a scenario before it starts: a line no step matches (with the closest step,
did you mean: I input Ada), a file that is not valid Gherkin, a scenario or step indented
differently from the others, and a file step pyathy cannot find in the program. It exits with
1 when it found something; --json prints the same for an editor (the pyathy VS Code
extension uses it). Details and sample output: docs/check.md.
Built-in steps, or your own
The built-in steps are the keyboard and the screen: type an answer, make the die show a
face, check what was printed, check a file. They need no code, so a feature can be read and
written by someone who has never seen a test; examples/tictactoe uses nothing else.
Your own steps speak the program's own language instead (Ann has $1440, Ann owns Harbour): a few lines of Python each, in a features/*_steps.py, worth writing once a feature
file starts repeating the same five built-in lines to say one thing.
Each built-in works after Given, When, Then, And or But. Text checks ignore case and
trailing spaces. Colours in the program's output (\033[31m-style codes) are ignored when
matching, and shown in the report. python pyathy steps prints this list (colour-coded on
a terminal: the parts you replace in cyan).
Each step has its own page under docs/, with what it checks, when it is
needed, a scenario that runs and the message it fails with. Two guides: turn-based
games (red rolls 6, red moves from 0 to 3) and starting from a saved
state (a saved game:, the program is started again).
First steps
| Step | What it does |
|---|---|
I start the program / I run the program with puzzle.txt --hard |
run main.py until it asks something or ends; with … starts it with these command-line arguments |
I input 4 / I input 4, left, no |
type answers, one per question |
"Hello" is printed |
somewhere in the output |
the program asks "Your name?" |
it is now waiting for input after that question |
"orange" is refused with a message |
after typing it, a message was printed and the same question was asked again (a menu printed every time is not the message; "" is pressing enter) |
the program ends / the program is still running |
Starting the program, and more output checks
| Step | What it does |
|---|---|
the program other.py |
run other.py instead of main.py |
the program may take 30 seconds |
wait longer for a slow program (default 10) |
main.py has DEBUG = True |
before it starts, set DEBUG = … at the top of main.py to this Python value (in the copy; your file stays as it is) |
main.py has a DEBUG setting |
main.py has DEBUG = … at the top, outside any function (only checks it is there; sets nothing) |
I input enter / I input enter, q |
press enter, on its own or as one answer of the list (quote "enter" to type the word) |
"Error" is printed 3 times |
exactly that many times |
"Game over" is not printed |
nowhere in the output |
the output starts with "Welcome" |
the very first output |
the output shows: + lines between """ |
these lines, in a row |
the line with "Total" also has "42" |
the last line printed with Total in it also has 42 |
the "Bob" row has "7" under "Score" / … has nothing under "Score" |
in the last table printed with a Score column (cells split by │ or |; tables lined up with spaces are not read), Bob's row has 7 there, or nothing |
Files and saved games
| Step | What it does |
|---|---|
a file "photos/beach.jpg" |
an empty file in the folder before the program starts (its folders made too) |
a file "game.txt" containing "round 3" |
put this one-line file in the folder before the program starts |
a file "game.txt" with: + lines between """ |
the same, several lines |
there is no file "game.txt" |
the program starts without it, whatever is in your folder (a saved game from playing, say) |
a file "game.txt" is written / no file is written |
the program made a file, or changed one |
the file "game.txt" contains "round 4" |
anywhere in the file |
the file "game.txt" contains: + lines between """ |
these lines, in a row |
a saved game: + lines between """ |
these lines are in the program's save file before it starts |
there is no saved game |
the program starts without its save file |
a saved game is written |
the program made its save file, or changed it |
the saved game holds: + lines between """ |
these lines, in a row, in the save file |
no saved game is left |
the save file was removed, or emptied |
the program is started again |
stop it and start it over in the same folder, so the files it wrote are still there |
Dice, random and turns
| Step | What it does |
|---|---|
I roll 6 / I roll 3 and 4 |
the next dice show these faces |
the random choice is red |
the next random pick returns this value |
the dice show 2, 4, 1 |
a line printed has these faces in this order, any separators but digits between them (2 4 1, [2, 4, 1]), no digit right next to them |
red rolls 6 / Ann rolls 4+6 |
I input enter (if the program is waiting for it) then I roll 6, after checking it is red's turn: the last line announcing a turn names red and no other player, without digits (Player red:) |
red rolls 3 and picks 2 / … and answers 2 |
the same, then types 2 at the question that follows |
these turns are played 3 times: + a table |
one step per row (| red rolls 5 |), run in order, that many times |
the players are red and green |
the names a turn announcement may use (otherwise: the names typed or rolled for so far) |
red's turn is announced / it is red's turn |
a line names red and no other player, without digits |
a pawn moves from 0 to 3 / red moves from 0 to 3 |
a line of this turn (since the last roll) has these two numbers, to or an arrow between them |
nothing moves |
no such line this turn |
Kim is named the winner |
a line printed names Kim, and no other player, and has won, wins, winner or win (case ignored) |
Dice or random choice? It depends on the random call:
- over exactly six consecutive whole numbers (
randint(1, 6),randrange(6),choice([1, 2, 3, 4, 5, 6])): a die, soI roll 4 - any other call (
randint(1, 10),choice(colours)):the random choice is 7, orred
Your own steps
Every *_steps.py next to the .feature files is loaded. A step is a pattern in
Cucumber style: {name} matches anything,
{name:w} one word, {n:d} a whole number, and each field becomes a parameter of the function.
program.settle() returns everything printed so far; fail(program, message) fails the step
with the program's last lines under the message.
examples/monopoly/features/monopoly_steps.py adds Ann has $1460 and Ann owns Harbour:
from pyathy.steps import fail, step
@step("{name:w} has ${cash:d}")
def has(program, name, cash):
...
python pyathy steps lists them under the built-ins, as written. The whole of it, with the
step above in full: docs/own-steps.md.
Examples
examples/tictactoe (built-in steps only), examples/sudoku (boards checked with
the output shows:, a puzzle file as argument) and examples/monopoly (dice and its own
steps). examples/edge fails on purpose, to show the messages. Run them all with
scripts/try-examples.sh.
Courses
pyathy pull and pyathy lock hand out and lock feature files; see docs/grading.md.
License
MIT, see LICENSE.
Metadata
Release files for pyathy 0.1.25
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyathy-0.1.25.tar.gz | 61.5 kB | With provenance | Details for pyathy-0.1.25.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyathy-0.1.25-py3-none-any.whl | Python 3 | none | any | Details for pyathy-0.1.25-py3-none-any.whl |
Total release size: 124.2 kB
Release files / pyathy-0.1.25.tar.gz
| Download URL | pyathy-0.1.25.tar.gz |
|---|---|
| Size | 61.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c9ad1ed6497b4632750ee4275fb5df08841f6f787744d059f3c1abdaca703ec7
|
|
BLAKE2b-256 checksum How to use checksums |
8095b647306dffdfe8943cdf80c528865fb058dea0ed77927db540780ff55281
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.
Transparency logRelease files / pyathy-0.1.25-py3-none-any.whl
| Download URL | pyathy-0.1.25-py3-none-any.whl |
|---|---|
| Size | 62.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4c8dcf53a041eead49f2da1aa090c4949a5545519425b05272961f6eb8896350
|
|
BLAKE2b-256 checksum How to use checksums |
c78d2184a51c2ca0c07140335120adea32d5c54068c1a01d837b9a83975d48b9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.
Transparency logSecurity for pyathy 0.1.25
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for pyathy-0.1.25.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.