Skip to content

Tutorial

This tutorial walks through setting up a small project, writing a test, and running it.

A new project

Initialise a project with uv and add a tests/ directory:

Bash
1
2
3
uv init --lib calculator
cd calculator
mkdir tests
Text Only
1
2
3
4
5
6
7
8
.
├── pyproject.toml
├── README.md
├── src
│   └── calculator
│       ├── __init__.py
│       └── py.typed
└── tests
src/calculator/__init__.py
1
2
3
class Calculator:
    def add(self, a: int, b: int) -> int:
        return a + b
tests/test_add.py
1
2
3
4
5
from calculator import Calculator

def test_add():
    calculator = Calculator()
    assert calculator.add(1, 2) == 3

Add Karva as a dev dependency and run the suite:

Bash
1
2
uv add --dev karva
uv run karva test

Where to next