Skip to content

veyra-snap: a Python library that writes pytest tests from real runs - #54

Merged
fcopensource merged 1 commit into
mainfrom
veyra-snap-python
Nov 22, 2026
Merged

fcopensource merged 1 commit into
mainfrom
veyra-snap-python

Conversation

@fcopensource

Copy link
Copy Markdown
Owner

veyra-snap: run your code, get pytest tests

A new Python library for PyPI, in python/veyra-snap/.

$ pip install veyra-snap
$ veyra-snap run app.py     # use your program as usual
$ veyra-snap write          # tests/test_snap_*.py
$ pytest                    # 25 passed

It records what the functions in your project are given and what they return or raise, then writes those real calls as readable, parametrized pytest tests. It's aimed at code without tests, nervous refactors, and locking down a library's behaviour.

How it works

  • No code changes. It uses sys.monitoring on Python 3.12+ and sys.settrace on 3.9–3.11. Your libraries, virtual environments and tests are never recorded, and a function stops being watched once it has 25 cases. Measured: library calls ×0.94 (no cost), a hot function of your own ×1.12.
  • Every value is rebuilt from its source and compared, type for type, before it goes in a test. Values that can't be rebuilt (files, connections, NaN…) are left out, with the reason shown.
  • Functions that change between calls (time, randomness) or only return None get no tests, so the generated tests are never flaky.
  • You can also record from code: recording() for a block, or @snap on chosen functions.
  • No dependencies. MIT licensed. Python 3.9+.

Tests

  • 71 tests. The end-to-end one runs the example shop, writes 25 tests, checks they pass, then changes a rounding rule and checks the generated tests catch it.
  • The wheel was installed into a brand-new environment and run there, and twine check passes.
  • This PR runs the new workflow on Linux, Windows and macOS with Python 3.9–3.14.

Publishing (after merge)

  1. On https://pypi.org/manage/account/publishing/, click Add a new pending publisher and enter: project veyra-snap, owner fcopensource, repository veyraeditor, workflow veyra-snap.yml, environment pypi.
  2. Go to Actions → veyra-snap (Python) → Run workflow → publish: pypi.

No tokens or passwords are stored anywhere (Trusted Publishing).

🤖 Generated with Claude Code

`pip install veyra-snap`, then `veyra-snap run app.py` and `veyra-snap write`:
it records what the functions in your project are given and what they
return or raise, and writes those real calls as readable pytest tests.

- No code changes: sys.monitoring on Python 3.12+ (code outside your project
  is never watched; a function with 25 cases stops being watched), and
  sys.settrace on 3.9-3.11. Or `recording()` / `@snap` in code.
- Every value is rebuilt from its source and compared, type for type, before
  it goes in a test; values that can't be (files, connections, NaN, ...) are
  left out with the reason shown.
- Functions that change between calls, or only return None, get no tests.
- No dependencies. 71 tests, including an end-to-end run whose generated tests
  pass and then catch a changed rounding rule.
- .github/workflows/veyra-snap.yml: tests on Linux, Windows and macOS with
  Python 3.9-3.14, and publishing to PyPI with Trusted Publishing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fcopensource
fcopensource merged commit dac6cc4 into main Nov 22, 2026
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants