Skip to content

Tutorial

This tutorial will walk you through the basics of using Karva.

Getting started

We will first create a new project using uv.

Bash
1
2
uv init --lib .
mkdir tests

This will give us a project that looks like this:

Text Only
1
2
3
4
5
6
7
8
.
├── pyproject.toml
├── README.md
├── src
│   └── karva_test
│       ├── __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

Then, we'll add karva to our project.

Bash
1
uv add --dev karva

We can then run our tests with uv run karva test.

Bash
1
uv run karva test