Pytest
Install
Create project using --package in uv:
Install pytest as a dev dependency:Directory Structure
- Create a 'tests' folder parallel to 'src' folder
- Mirror your src folder structure
- Pytest automatically discovers files that match
test_*.py - Test function names should start with
test_my_app/ ├── pyproject.toml ├── src/ │ └── my_app/ │ ├── __init__.py │ ├── core/ │ │ ├── __init__.py │ │ └── engine.py │ ├── utils/ │ │ ├── __init__.py │ │ └── math_utils.py │ └── main.py └── tests/ ├── __init__.py ├── core/ │ ├── __init__.py # optional │ └── test_engine.py ├── utils/ │ ├── __init__.py # optional │ └── test_math_utils.py └── test_main.py
Example
# tests/test_math_utils.py
from my_app.utils.math_utils import add
def test_add():
assert add(2, 3) == 5
Run Tests
Run tests using
Show more detailed output Run only tests in a specific file