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 |
|---|
| uv init --lib calculator
cd calculator
mkdir tests
|
| Text Only |
|---|
| .
├── pyproject.toml
├── README.md
├── src
│ └── calculator
│ ├── __init__.py
│ └── py.typed
└── tests
|
| src/calculator/__init__.py |
|---|
| class Calculator:
def add(self, a: int, b: int) -> int:
return a + b
|
| tests/test_add.py |
|---|
| 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 |
|---|
| uv add --dev karva
uv run karva test
|
Where to next