AgentStack
Browse Sign in
Browse Why AgentStack Sell Docs
Sign in
SKILL verified MIT Self-run

Python Testing

skill-bitwise-media-group-skills-python-testing · by bitwise-media-group

Python test authoring and review with pytest. Use when writing, adding, generating, or reviewing Python tests or unit tests for a function, module, or class; running pytest or a single test (the -k flag and other invocation flags for a Makefile or CI); parametrizing test cases into the table-driven pattern; setting up pytest fixtures or using the built-in tmp_path, monkeypatch, or capsys; choosin…

No reviews yet
0 installs
23 views
0.0% view→install

Install

$ agentstack add skill-bitwise-media-group-skills-python-testing

✓ scanned · ✓ verified, works with Claude Code, Cursor, and more.

Security review

✓ Passed

No issues found. Passed automated security review. · v0.1.0 How review works →

  • Prompt-injection patterns
  • Secret / credential exfiltration
  • Dangerous shell & filesystem operations
  • Untrusted network calls
  • Known-malicious package signatures

What it can access

  • Network access No
  • Filesystem access No
  • Shell / process execution No
  • Environment & secrets No
  • Dynamic code execution No

From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.

View the full security report →

Verified badge

Passed review? Show it. Paste this badge into your README, it links to the public security report.

AgentStack Verified badge Links to your public security report.
[![AgentStack Verified](https://agentstack.voostack.com/badges/verified.svg)](https://agentstack.voostack.com/security/report/skill-bitwise-media-group-skills-python-testing)

Reliability & compatibility

Security review passed
0 installs to date
no reviews yet
23d ago

Declared compatibility

Claude CodeClaude Desktop

Compatibility is declared by the source manifest. End-to-end runtime verification is coming, see below.

Preview Execution monitoring

We're building live execution health for every listing: tool-call success rate, median latency, uptime, and last-checked timestamps, measured, not self-reported. It isn't live yet, so we don't show numbers we can't stand behind.

How agent discovery & health will work →
Are you the author of Python Testing? Claim this listing to set pricing, connect Stripe payouts, and keep 70% of every sale.
Sign up to claim

About

Python testing conventions

pytest is the whole toolkit — plain assert, fixtures, parametrization, and Hypothesis for property tests. No unittest.TestCase boilerplate, no assertion DSLs. Tests live in tests/ and run with uv run pytest.

1. Parametrize instead of repeating

One test, a row per case — the table-driven pattern. Adding a behavior is adding a row:

import pytest

from myapp.kv import parse

@pytest.mark.parametrize(
    ("line", "want_key", "raises"),
    [
        ("a=b", "a", False),
        ("ab", None, True),       # missing separator
        ("=b", None, True),       # empty key
        ("a=", "a", False),       # empty value is fine
    ],
)
def test_parse(line: str, want_key: str | None, raises: bool) -> None:
    if raises:
        with pytest.raises(ValueError):
            parse(line)
    else:
        assert parse(line)[0] == want_key

Name each test for the behavior it pins down; assert directly — pytest rewrites it into a rich failure message.

2. Fixtures for setup, built-ins first

Shared setup is a @pytest.fixture; teardown goes after a yield. Reach for the built-in fixtures before inventing your own — tmp_path (a real temp directory), monkeypatch (patch env/attrs, auto-reverted), capsys (capture stdout/stderr). Put cross-file fixtures in tests/conftest.py.

3. Fakes over mocks

Prefer a small hand-written fake — a class with canned returns satisfying the consumer's Protocol (see python-typing) — to unittest.mock.MagicMock. Assert on observable behavior (return values, recorded state), not on which methods were called. Use monkeypatch to swap a dependency at a boundary; reserve mock for third-party seams you do not own, and avoid asserting call counts — they couple tests to implementation.

4. Property tests with Hypothesis

Every parser, encoder, or validator handling untrusted input gets a Hypothesis test — the analogue of Go's native fuzzing. Generate inputs and assert the invariants that must hold for any input (no crash, round-trips, never emits an invalid result):

from hypothesis import given, strategies as st

from myapp.kv import parse

@given(st.text())
def test_parse_never_crashes(s: str) -> None:
    try:
        key, _ = parse(s)
    except ValueError:
        return  # rejecting bad input is fine
    assert key != ""  # but a parsed key is never empty

Hypothesis shrinks any failing case to a minimal example and records it, so the regression replays on every run. Use @given with explicit strategies; seed known tricky cases with @example.

5. Invocations

uv run pytest                 # the suite (unit + property tests)
uv run pytest -q              # quiet, for the make/CI gate
uv run pytest -k name         # run tests matching an expression
uv run pytest --cov=myapp     # coverage (needs the pytest-cov dev dependency)

make test runs uv run pytest (see python-project); CI runs the same (see python-release). For the interfaces that make code testable see python-typing; for house style see python-style.

Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

Install and usage instructions live in the source repository linked above.

Reviews

No reviews yet, be the first.

Versions

  • v0.1.0 Imported from the upstream source.