← ClaudeAtlas

py-testinglisted

Python testing advisor. Always use this skill when writing Python tests, working with pytest, fixtures, conftest, mocking, patching, or parametrize. Use when the user asks "how do I mock this in Python", "how do I patch a function", "where should I patch", "why isn't my patch working", "how do I parametrize tests", "how do I test async Python code", "how do I use fixtures", or "pytest conftest". Read this skill before writing any Python test or debugging a failing mock or patch.
AllThingsSmitty/agent-skills · ★ 1 · Testing & QA · score 74
Install: claude install-skill AllThingsSmitty/agent-skills
# Python Testing pytest is the standard. Its fixture system is more composable than unittest's setUp/tearDown, its output is more readable, and parametrize eliminates test duplication cleanly. Use it. ## Fixtures Fixtures are pytest's dependency injection system. A test declares what it needs; pytest provides it. ```python # conftest.py — fixtures available to all tests in the directory import pytest from myapp.db import Database @pytest.fixture def db(): database = Database(':memory:') database.migrate() yield database # yield instead of return for teardown database.close() # runs after the test completes # test_users.py def test_create_user(db): # pytest injects the db fixture user = db.create_user('Alice') assert user.name == 'Alice' ``` **Scope**: fixtures run once per test by default. Use `scope='module'` or `scope='session'` for expensive resources (database connections, containers) that are safe to share: ```python @pytest.fixture(scope='session') def db_connection(): conn = create_connection() yield conn conn.close() ``` **conftest.py** — put shared fixtures here, not in individual test files. pytest discovers conftest.py automatically at every directory level. ## Parametrize Replace repeated test functions with `@pytest.mark.parametrize`: ```python # Bad: three functions testing the same logic with different inputs def test_valid_email_with_plus(): ... def test_valid_email_simple(): ... def test_invali