Home / UV / Chapter 4

Chapter 4: Running commands

Oct 9, 2024
4 of 7

Running commands is as easy as calling uv run. For example, lets add a simple test case at tests/test_main.py

tests/main.py
def test_main():
    assert True

Running pytest in your environment can be done with

uv run pytest

UV is so quick that it resyncs and locks the environment on every run command. If you manually edit the pyproject.toml file to add the requests library:

pyproject.toml
[project]
name = "yt-uv"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.8"
dependencies = [
    "typer>=0.12.4",
    "requests",
]

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.uv]
dev-dependencies = [
    "pytest>=8.3.2",
]

import requests into the test file:

tests/test_main.py
import requests

def test_main():
    assert True

and run

uv run pytest

UV quickly resolve all dependencies, updates the lock file and runs the test, all blazingly fast.