veyra-snap icon
NEW · PYTHON LIBRARY

veyra-snap

Run your code. Get pytest tests.

veyra-snap watches your program run, records what each of your functions was given and what it returned or raised, and writes those real calls as ready-to-run pytest tests. A safety net for code without tests, in one command.

pip install veyra-snap
Official package on PyPI · by FlightCodershttps://pypi.org/project/veyra-snap/

v1.0.0 · Free · MIT · Python 3.9+ · No dependencies · Windows, macOS, Linux

terminal: the example shop
$ veyra-snap run app.py          # use your program as usual
◆ veyra-snap  recorded 38 calls in 8 functions, 27 new cases
  shop.cart.discount      5 cases  (1 raise)
  shop.cart.line_total    3 cases
  shop.cart.price         6 cases  (2 raises)
  shop.cart.subtotal      4 cases
  shop.text.new_order_id  1 case  changes between calls: no tests
  shop.text.order_number  4 cases
  shop.text.slugify       3 cases
  ! shop.text.write_receipt: 4 calls left out (an argument: StringIO values can't be written as source)

$ veyra-snap write
  ✓ tests/test_snap_shop_cart.py  18 cases in 6 tests
  ✓ tests/test_snap_shop_text.py  7 cases in 2 tests
◆ veyra-snap  wrote 25 test cases. Run them: pytest

$ pytest
25 passed in 0.05s
FEATURES

A test suite from one run.

No code changes

Run your script or module with veyra-snap run. It watches the functions in your project while your program does what it always does.

Every value double-checked

Each argument and result is written as Python source and rebuilt to make sure it comes back the same, type for type, before it goes in a test.

No flaky tests

If the same arguments ever give a different result (time, randomness, a database), the function gets no tests. Functions that only return None are skipped too.

Errors, too

Calls that raise become tests that expect that exception with that exact message, so a changed error is caught as well.

Tests you can read

Plain parametrized pytest, one test per function, each case named after its call. Review it, commit it, edit what looks wrong.

Your code only

The standard library, your installed packages, virtual environments and your tests are never recorded.

Fast

On Python 3.12+ it uses sys.monitoring: library code costs nothing, and a function stops being watched once it has 25 cases. Hot loops stay fast.

Record more any time

Every run adds new cases to .veyra-snap/ and veyra-snap write regenerates the files. It never touches a test file it didn’t write.

Free, local, no dependencies

Pure Python, MIT licensed, nothing sent anywhere. Python 3.9 to 3.14 on Windows, macOS and Linux.

WHAT YOU GET

Plain pytest you can read.

This is part of what veyra-snap wrote for the example shop. Change how discounts round, and these tests fail.

tests/test_snap_shop_cart.py
@pytest.mark.parametrize(
    "args, kwargs, expected",
    [
        pytest.param((decimal.Decimal('24.00'), None), {}, decimal.Decimal('0'), id="discount(decimal.Decimal('24.00'), None)"),
        pytest.param((decimal.Decimal('38.00'), 'welcome10'), {}, decimal.Decimal('3.80'), id="discount(decimal.Decimal('38.00'), 'welcome10')"),
        pytest.param((decimal.Decimal('64.50'), 'VIP25'), {}, decimal.Decimal('16.13'), id="discount(decimal.Decimal('64.50'), 'VIP25')"),
    ],
)
def test_discount(args, kwargs, expected):
    assert shop.cart.discount(*args, **kwargs) == expected


@pytest.mark.parametrize(
    "args, kwargs, error, message",
    [
        pytest.param((decimal.Decimal('24.00'), 'FREEBIE'), {}, ValueError, "unknown coupon 'FREEBIE'", id="discount(decimal.Decimal('24.00'), 'FREEBIE')"),
    ],
)
def test_discount_raises(args, kwargs, error, message):
    with pytest.raises(error) as caught:
        shop.cart.discount(*args, **kwargs)
    assert str(caught.value) == message
HOW IT WORKS

Record. Check. Write.

  1. 1

    Record

    veyra-snap run app.py runs your program and notes what each function in your project was given, and what it returned or raised.

  2. 2

    Check

    Every value is rebuilt from source and compared. Values that can't be, and functions that change between calls, are left out, with the reason shown.

  3. 3

    Write

    veyra-snap write turns the recordings into tests/test_snap_<module>.py. Run pytest, and commit the tests.

Or from your code

Record a block with with recording():, or mark the functions you care about with @snap. @snap costs nothing in normal runs; it records under veyra-snap run, inside recording(), or with VEYRA_SNAP=1.

Values it can write

Nested any way you like:

  • None
  • bool
  • int
  • float
  • str
  • bytes
  • list
  • tuple
  • dict
  • set
  • Decimal
  • Fraction
  • datetime
  • date
  • timedelta
  • UUID
  • Enum
  • dataclasses
  • NamedTuple
INSTALL

Ready in a minute.

  1. Install it from PyPI:
    pip install veyra-snap
  2. In your project, run your program with veyra-snap run app.py, or veyra-snap run -m yourpackage.
  3. Run veyra-snap write, then pytest.

The official package is pypi.org/project/veyra-snap, published by FlightCoders. The source, docs and changelog are on GitHub. For JavaScript, try Veyra Live Values, which shows console.log values next to your code, and Veyra Blast Radius, which runs only the tests your change affects.

commandsveyra-snap run app.py ▸ record
veyra-snap write ▸ tests/
veyra-snap show --cases ▸ what's recorded
veyra-snap clear ▸ start over
FAQ

Questions

What is veyra-snap for?

Getting a safety net fast. Code without tests, a refactor you’re nervous about, a library whose behaviour you want to lock down: run it once under veyra-snap and you have regression tests for what it does today.

Do the tests prove my code is correct?

No. They record what your code does now, bugs included, so you notice when that changes. Read them, and fix what looks wrong; they’re a starting point you own.

Do I have to change my code?

No. veyra-snap run app.py (or run -m yourpackage) records everything. If you prefer, mark chosen functions with @snap, or record a block with "with recording():".

What about values it can’t write, like open files or database connections?

Those calls are left out, and veyra-snap tells you which ones and why. Everything that does go in a test has been rebuilt from its source and compared first.

Which Python versions?

Python 3.9 to 3.14. On 3.12+ recording uses sys.monitoring and records raised errors automatically; on 3.9 to 3.11 it uses sys.settrace, and errors are recorded for functions marked with @snap.

Is it free?

Yes. veyra-snap is free and open source under the MIT license, with no account and no telemetry. It’s made by FlightCoders, the team behind the Veyra editor.

Made by the Veyra team.

Veyra Studio is a fast, free code editor with Python debugging, Live Server and Search Everywhere built in.

Download VeyraView on GitHub