pytest

9.0.2 · active · verified Wed Mar 25

The standard Python testing framework. Supports fixtures, parametrize, markers, plugins, and assertion rewriting. Current version is 9.0.2. Major versions (8.x, 9.x) have removed long-deprecated features that LLMs still generate.

Warnings

Install

Imports

Quickstart

Basic fixture and parametrize usage. Run with: pytest -v

# test_example.py
import pytest

@pytest.fixture
def sample_data():
    return {"key": "value"}

def test_basic(sample_data):
    assert sample_data["key"] == "value"

@pytest.mark.parametrize("x,expected", [(1, 2), (2, 4)])
def test_double(x, expected):
    assert x * 2 == expected

# Run: pytest -v

view raw JSON →