Pytest

Writes Python tests with pytest, including fixtures, parameterization, and plugins for coverage. Use when this capability is needed.

tomevault-io Updated

File contents

Pytest

Python testing framework with fixtures and parameterized tests.

Quick Start

def test_add(): assert 1 + 1 == 2
def test_subtract(): assert 3 - 1 == 2
pytest test_calc.py -v

Fixtures & Parameterization

import pytest
@pytest.fixture
def db_connection(): conn = create_database(); yield conn; conn.close()
@pytest.mark.parametrize("input,expected", [(1, 2), (2, 4), (3, 6)])
def test_double(input, expected): assert input * 2 == expected

When to Use

  • Python unit tests; API testing; Data pipeline validation; TDD

Validation

  1. pytest discovers all tests; 2. Fixtures setup/teardown correctly; 3. Coverage reports

Source: ssrjkk/claude-skills — distributed by TomeVault.

tomevault-io/skills-registry/tree/main/ssrjkk--claude-skills--pytest commit 191eb254a2

Frequently asked questions

npx skillmds@latest add tomevault-io/pytest-5