agentsclimarketplace

Pytest

Skill G1Joshi/Agent-Skills/skills/testing/pytest

A comprehensive skill catalog for AI agents

Install
npx -y skills add G1Joshi/Agent-Skills --skill pytest

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 10 stars10 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its author says it does

Copied from the file, not written here

pytest Python testing framework with fixtures. Use for Python testing.

SKILL.md

1.8 KB, as published. Nobody here has run it

Pytest

Pytest is the dominant testing framework for Python. It is loved for its no-boilerplate syntax (assert x == y), powerful fixture system, and rich plugin ecosystem.

When to Use

  • Python Projects: The standard for 99% of new Python projects.
  • Complex Setup: Use Fixtures to handle database connections, API clients, or mock data.
  • Parametrization: Running the same test with different inputs.

Quick Start

# content of test_sample.py
def inc(x):
    return x + 1

def test_answer():
    assert inc(3) == 5

Running it:

pytest

Core Concepts

Fixtures

Functions that run before tests to set up state. They are injected via argument name matching.

import pytest

@pytest.fixture
def database():
    db = connect_db()
    yield db
    db.close()

def test_insert(database):
    database.insert("user")
    assert database.count() == 1

Parametrization

Decorating a test to run multiple times.

@pytest.mark.parametrize("input,expected", [
    ("3+5", 8),
    ("2+4", 6),
])
def test_eval(input, expected):
    assert eval(input) == expected

Best Practices (2025)

Do:

  • Use conftest.py: Place shared fixtures here. Pytest discovers them automatically.
  • Use pytest-cov: For coverage reports (pytest --cov=src).
  • Use Markers: Tag slow tests (@pytest.mark.slow) and exclude them during dev (pytest -m "not slow").

Don't:

  • Don't use unittest.TestCase: Unless migrating legacy code. Functional tests are cleaner.
  • Don't use global state: Fixtures should return fresh instances.

References

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.