agentleFS
amirrezaalastiamirrezaalasti/codescribe/skills/coding/python-testing/SKILL.md

python-testing

Skill2 starsChanged 4 months agoMITView on GitHub

Design and write pytest tests with clear fixtures, parametrization, and coverage expectations. Use when writing Python tests, fixing failing tests, adding fixtures, or when the user mentions pytest, unit tests, or test coverage in Python.

70 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use python-patterns, django-verification and 10 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • xenitV1Skill

    python-patterns

    Python development principles and decision-making. Framework selection, async patterns, type hints, project structure. Teaches thinking, not copying.

    Also in 25 projects that use this

  • mstuder-slalomSkill

    django-verification

    Verification loop for Django projects: migrations, linting, tests with coverage, security scans, and deployment readiness checks before release or PR.

    Also in 9 projects that use this

  • HABUBUSSSkill

    project-guidelines-example

    Also in 8 projects that use this

  • mstuder-slalomSkill

    springboot-security

    Spring Security best practices for authn/authz, validation, CSRF, secrets, headers, rate limiting, and dependency security in Java Spring Boot services.

    Also in 8 projects that use this

  • AshfaqbsSkill

    springboot-tdd

    Test-driven development for Spring Boot using JUnit 5, Mockito, MockMvc, Testcontainers, and JaCoCo. Use when adding features, fixing bugs, or refactoring.

    Also in 7 projects that use this

  • nek1987Skill

    postgres-patterns

    PostgreSQL patterns for reviewing migrations and writing efficient queries. Use when reviewing Alembic migrations, optimizing queries, or debugging database issues.

    Also in 16 projects that use this

  • +1 more from mstuder-slalom

The file

We split this skill into the rules it gives an agent

8 rules. 0 are common, 3 are distinctive, and 5 are very specific to this project.

  • 0

    Common

    Most of the 64 edited versions we read keep these.

  • 3

    Distinctive

    This author's own choices. Worth a look.

  • 5

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Arrange → Act → Assert: Keep each test focused on one behavior.

    line 27
  2. Very specific:

    Use fixtures for shared setup: Prefer function-scoped fixtures.

    line 28
  3. Very specific:

    Parametrize similar cases: Use @pytest.mark.parametrize for input tables instead of copy-pasted tests.

    line 29
  4. Very specific:

    Mark slow / integration tests: Use markers (@pytest.mark.slow, @pytest.mark.integration) when the project defines them.

    line 30
  5. Very specific:

    Fail loudly: Prefer raising / expecting exceptions with pytest.raises over returning magic error codes in tests.

    line 32
  6. Very specific:

    Tag gaps: If you skip coverage for a path you touched, leave 🟠 TEST(P1): via tagged-code-comments and list it in Open follow-ups so the …

    line 33
  7. Distinctive:

    Prefer critical-path and edge-case coverage over 100% line chasing

    line 53
  8. Distinctive:

    Do not weaken assertions just to make coverage green

    line 54

“Common” is measured: kept by at least 6 in 10 of the 64 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Python Testing (pytest)

Defaults

  • Framework: pytest
  • Layout: tests/ mirroring the package, or colocated test_*.py if the repo already does that
  • Naming: test_<behavior>, files test_<module>.py
  • Assertions: plain assert with readable messages when helpful

Instructions

  1. Test behavior, not implementation. Assert outcomes users care about (return values, side effects, errors). Avoid brittle private-API tests.
  2. Arrange → Act → Assert. Keep each test focused on one behavior.
  3. Use fixtures for shared setup. Prefer function-scoped fixtures; use yield for teardown. Avoid fixture pyramids — extract helpers when fixtures nest deeply.
  4. Parametrize similar cases. Use @pytest.mark.parametrize for input tables instead of copy-pasted tests.
  5. Mark slow / integration tests. Use markers (@pytest.mark.slow, @pytest.mark.integration) when the project defines them; keep the default suite fast.
  6. Mock at boundaries. Mock network, clock, and filesystem edges — not the unit under test. Prefer unittest.mock or pytest-mock as the project already uses.
  7. Fail loudly. Prefer raising / expecting exceptions with pytest.raises over returning magic error codes in tests.
  8. Tag gaps. If you skip coverage for a path you touched, leave 🟠 TEST(P1): via tagged-code-comments and list it in Open follow-ups so the developer must check before ship.

Minimal example

import pytest
from mypkg.mathutil import divide

@pytest.mark.parametrize("a,b,expected", [(6, 3, 2), (5, 2, 2.5)])
def test_divide(a, b, expected):
    assert divide(a, b) == expected

def test_divide_by_zero():
    with pytest.raises(ZeroDivisionError):
        divide(1, 0)

Coverage expectations

  • New logic should have tests unless the user says otherwise
  • Prefer critical-path and edge-case coverage over 100% line chasing
  • Do not weaken assertions just to make coverage green

Anti-patterns

  • One giant test that asserts everything
  • Sleeping for timing instead of controlling time
  • Snapshotting entire large objects when a few fields matter
  • Tests that depend on run order or shared mutable module state

Additional resources

  • references/checklist.md

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.