[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M72WXM9QHA54AYYABPDT2QRX":3,"skill-same:01M72WXM9QHA54AYYABPDT2QRX":53},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":30,"commitSha":31,"skillDirectory":32,"forksCount":33,"repositoryHtmlUrl":34,"repositoryHomepageUrl":6,"ownerHtmlUrl":35,"ownerBlogUrl":36,"ownerDescription":37,"updatedAt":38,"install":39,"resources":52},"01M72WXM9QHA54AYYABPDT2QRX","python-testing",null,"Python testing best practices using pytest including fixtures, parametrization, mocking, coverage analysis, async testing, and test organization. Use when writing or improving Python tests.","SriramGandhiS\u002FSkills","SriramGandhiS","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F211849986?v=4","01M72WQCW12BYX71C6WN584TTA","Sriram S","01M72WQCWTJ2RD0ET1X31AF1RC",1,"MIT","https:\u002F\u002Fgithub.com\u002FSriramGandhiS\u002FSkills\u002Fblob\u002Fmaster\u002F.kiro\u002Fskills\u002Fpython-testing\u002FSKILL.md",[],[],"2026-11-10 22:39:42",false,"---\nname: python-testing\ndescription: >\n  Python testing best practices using pytest including fixtures, parametrization,\n  mocking, coverage analysis, async testing, and test organization. Use when\n  writing or improving Python tests.\nmetadata:\n  origin: ECC\n  globs: [\"**\u002F*.py\", \"**\u002F*.pyi\"]\n---\n\n# Python Testing\n\n> This skill provides comprehensive Python testing patterns using pytest as the primary testing framework.\n\n## Testing Framework\n\nUse **pytest** as the testing framework for its powerful features and clean syntax.\n\n### Basic Test Structure\n\n```python\ndef test_user_creation():\n    \"\"\"Test that a user can be created with valid data\"\"\"\n    user = User(name=\"Alice\", email=\"alice@example.com\")\n\n    assert user.name == \"Alice\"\n    assert user.email == \"alice@example.com\"\n    assert user.is_active is True\n```\n\n### Test Discovery\n\npytest automatically discovers tests following these conventions:\n- Files: `test_*.py` or `*_test.py`\n- Functions: `test_*`\n- Classes: `Test*` (without `__init__`)\n- Methods: `test_*`\n\n## Fixtures\n\nFixtures provide reusable test setup and teardown:\n\n```python\nimport pytest\nfrom sqlalchemy import create_engine\nfrom sqlalchemy.orm import sessionmaker\n\n@pytest.fixture\ndef db_session():\n    \"\"\"Provide a database session for tests\"\"\"\n    engine = create_engine(\"sqlite:\u002F\u002F\u002F:memory:\")\n    Session = sessionmaker(bind=engine)\n    session = Session()\n\n    # Setup\n    Base.metadata.create_all(engine)\n\n    yield session\n\n    # Teardown\n    session.close()\n\ndef test_user_repository(db_session):\n    \"\"\"Test using the db_session fixture\"\"\"\n    repo = UserRepository(db_session)\n    user = repo.create(name=\"Alice\", email=\"alice@example.com\")\n\n    assert user.id is not None\n```\n\n### Fixture Scopes\n\n```python\n@pytest.fixture(scope=\"function\")  # Default: per test\ndef user():\n    return User(name=\"Alice\")\n\n@pytest.fixture(scope=\"class\")  # Per test class\ndef database():\n    db = Database()\n    db.connect()\n    yield db\n    db.disconnect()\n\n@pytest.fixture(scope=\"module\")  # Per module\ndef app():\n    return create_app()\n\n@pytest.fixture(scope=\"session\")  # Once per test session\ndef config():\n    return load_config()\n```\n\n### Fixture Dependencies\n\n```python\n@pytest.fixture\ndef database():\n    db = Database()\n    db.connect()\n    yield db\n    db.disconnect()\n\n@pytest.fixture\ndef user_repository(database):\n    \"\"\"Fixture that depends on database fixture\"\"\"\n    return UserRepository(database)\n\ndef test_create_user(user_repository):\n    user = user_repository.create(name=\"Alice\")\n    assert user.id is not None\n```\n\n## Parametrization\n\nTest multiple inputs with `@pytest.mark.parametrize`:\n\n```python\nimport pytest\n\n@pytest.mark.parametrize(\"email,expected\", [\n    (\"user@example.com\", True),\n    (\"invalid-email\", False),\n    (\"\", False),\n    (\"user@\", False),\n    (\"@example.com\", False),\n])\ndef test_email_validation(email, expected):\n    result = validate_email(email)\n    assert result == expected\n```\n\n### Multiple Parameters\n\n```python\n@pytest.mark.parametrize(\"name,age,valid\", [\n    (\"Alice\", 25, True),\n    (\"Bob\", 17, False),\n    (\"\", 25, False),\n    (\"Charlie\", -1, False),\n])\ndef test_user_validation(name, age, valid):\n    result = validate_user(name, age)\n    assert result == valid\n```\n\n### Parametrize with IDs\n\n```python\n@pytest.mark.parametrize(\"input,expected\", [\n    (\"hello\", \"HELLO\"),\n    (\"world\", \"WORLD\"),\n], ids=[\"lowercase\", \"another_lowercase\"])\ndef test_uppercase(input, expected):\n    assert input.upper() == expected\n```\n\n## Test Markers\n\nUse markers for test categorization and selective execution:\n\n```python\nimport pytest\n\n@pytest.mark.unit\ndef test_calculate_total():\n    \"\"\"Fast unit test\"\"\"\n    assert calculate_total([1, 2, 3]) == 6\n\n@pytest.mark.integration\ndef test_database_connection():\n    \"\"\"Slower integration test\"\"\"\n    db = Database()\n    assert db.connect() is True\n\n@pytest.mark.slow\ndef test_large_dataset():\n    \"\"\"Very slow test\"\"\"\n    process_million_records()\n\n@pytest.mark.skip(reason=\"Not implemented yet\")\ndef test_future_feature():\n    pass\n\n@pytest.mark.skipif(sys.version_info \u003C (3, 10), reason=\"Requires Python 3.10+\")\ndef test_new_syntax():\n    pass\n```\n\n**Run specific markers:**\n```bash\npytest -m unit              # Run only unit tests\npytest -m \"not slow\"        # Skip slow tests\npytest -m \"unit or integration\"  # Run unit OR integration\n```\n\n## Mocking\n\n### Using unittest.mock\n\n```python\nfrom unittest.mock import Mock, patch, MagicMock\n\ndef test_user_service_with_mock():\n    \"\"\"Test with mock repository\"\"\"\n    mock_repo = Mock()\n    mock_repo.find_by_id.return_value = User(id=\"1\", name=\"Alice\")\n\n    service = UserService(mock_repo)\n    user = service.get_user(\"1\")\n\n    assert user.name == \"Alice\"\n    mock_repo.find_by_id.assert_called_once_with(\"1\")\n\n@patch('myapp.services.EmailService')\ndef test_send_notification(mock_email_service):\n    \"\"\"Test with patched dependency\"\"\"\n    service = NotificationService()\n    service.send(\"user@example.com\", \"Hello\")\n\n    mock_email_service.send.assert_called_once()\n```\n\n### pytest-mock Plugin\n\n```python\ndef test_with_mocker(mocker):\n    \"\"\"Using pytest-mock plugin\"\"\"\n    mock_repo = mocker.Mock()\n    mock_repo.find_by_id.return_value = User(id=\"1\", name=\"Alice\")\n\n    service = UserService(mock_repo)\n    user = service.get_user(\"1\")\n\n    assert user.name == \"Alice\"\n```\n\n## Coverage Analysis\n\n### Basic Coverage\n\n```bash\npytest --cov=src --cov-report=term-missing\n```\n\n### HTML Coverage Report\n\n```bash\npytest --cov=src --cov-report=html\nopen htmlcov\u002Findex.html\n```\n\n### Coverage Configuration\n\n```ini\n# pytest.ini or pyproject.toml\n[tool.pytest.ini_options]\naddopts = \"\"\"\n    --cov=src\n    --cov-report=term-missing\n    --cov-report=html\n    --cov-fail-under=80\n\"\"\"\n```\n\n### Branch Coverage\n\n```bash\npytest --cov=src --cov-branch\n```\n\n## Async Testing\n\n### Testing Async Functions\n\n```python\nimport pytest\n\n@pytest.mark.asyncio\nasync def test_async_fetch_user():\n    \"\"\"Test async function\"\"\"\n    user = await fetch_user(\"1\")\n    assert user.name == \"Alice\"\n\n@pytest.fixture\nasync def async_client():\n    \"\"\"Async fixture\"\"\"\n    client = AsyncClient()\n    await client.connect()\n    yield client\n    await client.disconnect()\n\n@pytest.mark.asyncio\nasync def test_with_async_fixture(async_client):\n    result = await async_client.get(\"\u002Fusers\u002F1\")\n    assert result.status == 200\n```\n\n## Test Organization\n\n### Directory Structure\n\n```\ntests\u002F\n├── unit\u002F\n│   ├── test_models.py\n│   ├── test_services.py\n│   └── test_utils.py\n├── integration\u002F\n│   ├── test_database.py\n│   └── test_api.py\n├── conftest.py          # Shared fixtures\n└── pytest.ini           # Configuration\n```\n\n### conftest.py\n\n```python\n# tests\u002Fconftest.py\nimport pytest\n\n@pytest.fixture(scope=\"session\")\ndef app():\n    \"\"\"Application fixture available to all tests\"\"\"\n    return create_app()\n\n@pytest.fixture\ndef client(app):\n    \"\"\"Test client fixture\"\"\"\n    return app.test_client()\n\ndef pytest_configure(config):\n    \"\"\"Register custom markers\"\"\"\n    config.addinivalue_line(\"markers\", \"unit: Unit tests\")\n    config.addinivalue_line(\"markers\", \"integration: Integration tests\")\n    config.addinivalue_line(\"markers\", \"slow: Slow tests\")\n```\n\n## Assertions\n\n### Basic Assertions\n\n```python\ndef test_assertions():\n    assert value == expected\n    assert value != other\n    assert value > 0\n    assert value in collection\n    assert isinstance(value, str)\n```\n\n### pytest Assertions with Better Error Messages\n\n```python\ndef test_with_context():\n    \"\"\"pytest provides detailed assertion introspection\"\"\"\n    result = calculate_total([1, 2, 3])\n    expected = 6\n\n    # pytest shows: assert 5 == 6\n    assert result == expected\n```\n\n### Custom Assertion Messages\n\n```python\ndef test_with_message():\n    result = process_data(input_data)\n    assert result.is_valid, f\"Expected valid result, got errors: {result.errors}\"\n```\n\n### Approximate Comparisons\n\n```python\nimport pytest\n\ndef test_float_comparison():\n    result = 0.1 + 0.2\n    assert result == pytest.approx(0.3)\n\n    # With tolerance\n    assert result == pytest.approx(0.3, abs=1e-9)\n```\n\n## Exception Testing\n\n```python\nimport pytest\n\ndef test_raises_exception():\n    \"\"\"Test that function raises expected exception\"\"\"\n    with pytest.raises(ValueError):\n        validate_age(-1)\n\ndef test_exception_message():\n    \"\"\"Test exception message\"\"\"\n    with pytest.raises(ValueError, match=\"Age must be positive\"):\n        validate_age(-1)\n\ndef test_exception_details():\n    \"\"\"Capture and inspect exception\"\"\"\n    with pytest.raises(ValidationError) as exc_info:\n        validate_user(name=\"\", age=-1)\n\n    assert \"name\" in exc_info.value.errors\n    assert \"age\" in exc_info.value.errors\n```\n\n## Test Helpers\n\n```python\n# tests\u002Fhelpers.py\ndef assert_user_equal(actual, expected):\n    \"\"\"Custom assertion helper\"\"\"\n    assert actual.id == expected.id\n    assert actual.name == expected.name\n    assert actual.email == expected.email\n\ndef create_test_user(**kwargs):\n    \"\"\"Test data factory\"\"\"\n    defaults = {\n        \"name\": \"Test User\",\n        \"email\": \"test@example.com\",\n        \"age\": 25,\n    }\n    defaults.update(kwargs)\n    return User(**defaults)\n```\n\n## Property-Based Testing\n\nUsing `hypothesis` for property-based testing:\n\n```python\nfrom hypothesis import given, strategies as st\n\n@given(st.integers(), st.integers())\ndef test_addition_commutative(a, b):\n    \"\"\"Test that addition is commutative\"\"\"\n    assert a + b == b + a\n\n@given(st.lists(st.integers()))\ndef test_sort_idempotent(lst):\n    \"\"\"Test that sorting twice gives same result\"\"\"\n    sorted_once = sorted(lst)\n    sorted_twice = sorted(sorted_once)\n    assert sorted_once == sorted_twice\n```\n\n## Best Practices\n\n1. **One assertion per test** (when possible)\n2. **Use descriptive test names** - describe what's being tested\n3. **Arrange-Act-Assert pattern** - clear test structure\n4. **Use fixtures for setup** - avoid duplication\n5. **Mock external dependencies** - keep tests fast and isolated\n6. **Test edge cases** - empty inputs, None, boundaries\n7. **Use parametrize** - test multiple scenarios efficiently\n8. **Keep tests independent** - no shared state between tests\n\n## Running Tests\n\n```bash\n# Run all tests\npytest\n\n# Run specific file\npytest tests\u002Ftest_user.py\n\n# Run specific test\npytest tests\u002Ftest_user.py::test_create_user\n\n# Run with verbose output\npytest -v\n\n# Run with output capture disabled\npytest -s\n\n# Run in parallel (requires pytest-xdist)\npytest -n auto\n\n# Run only failed tests from last run\npytest --lf\n\n# Run failed tests first\npytest --ff\n```\n\n## When to Use This Skill\n\n- Writing new Python tests\n- Improving test coverage\n- Setting up pytest infrastructure\n- Debugging flaky tests\n- Implementing integration tests\n- Testing async Python code\n","# Python Testing\n\n> This skill provides comprehensive Python testing patterns using pytest as the primary testing framework.\n\n## Testing Framework\n\nUse **pytest** as the testing framework for its powerful features and clean syntax.\n\n### Basic Test Structure\n\n```python\ndef test_user_creation():\n    \"\"\"Test that a user can be created with valid data\"\"\"\n    user = User(name=\"Alice\", email=\"alice@example.com\")\n\n    assert user.name == \"Alice\"\n    assert user.email == \"alice@example.com\"\n    assert user.is_active is True\n```\n\n### Test Discovery\n\npytest automatically discovers tests following these conventions:\n- Files: `test_*.py` or `*_test.py`\n- Functions: `test_*`\n- Classes: `Test*` (without `__init__`)\n- Methods: `test_*`\n\n## Fixtures\n\nFixtures provide reusable test setup and teardown:\n\n```python\nimport pytest\nfrom sqlalchemy import create_engine\nfrom sqlalchemy.orm import sessionmaker\n\n@pytest.fixture\ndef db_session():\n    \"\"\"Provide a database session for tests\"\"\"\n    engine = create_engine(\"sqlite:\u002F\u002F\u002F:memory:\")\n    Session = sessionmaker(bind=engine)\n    session = Session()\n\n    # Setup\n    Base.metadata.create_all(engine)\n\n    yield session\n\n    # Teardown\n    session.close()\n\ndef test_user_repository(db_session):\n    \"\"\"Test using the db_session fixture\"\"\"\n    repo = UserRepository(db_session)\n    user = repo.create(name=\"Alice\", email=\"alice@example.com\")\n\n    assert user.id is not None\n```\n\n### Fixture Scopes\n\n```python\n@pytest.fixture(scope=\"function\")  # Default: per test\ndef user():\n    return User(name=\"Alice\")\n\n@pytest.fixture(scope=\"class\")  # Per test class\ndef database():\n    db = Database()\n    db.connect()\n    yield db\n    db.disconnect()\n\n@pytest.fixture(scope=\"module\")  # Per module\ndef app():\n    return create_app()\n\n@pytest.fixture(scope=\"session\")  # Once per test session\ndef config():\n    return load_config()\n```\n\n### Fixture Dependencies\n\n```python\n@pytest.fixture\ndef database():\n    db = Database()\n    db.connect()\n    yield db\n    db.disconnect()\n\n@pytest.fixture\ndef user_repository(database):\n    \"\"\"Fixture that depends on database fixture\"\"\"\n    return UserRepository(database)\n\ndef test_create_user(user_repository):\n    user = user_repository.create(name=\"Alice\")\n    assert user.id is not None\n```\n\n## Parametrization\n\nTest multiple inputs with `@pytest.mark.parametrize`:\n\n```python\nimport pytest\n\n@pytest.mark.parametrize(\"email,expected\", [\n    (\"user@example.com\", True),\n    (\"invalid-email\", False),\n    (\"\", False),\n    (\"user@\", False),\n    (\"@example.com\", False),\n])\ndef test_email_validation(email, expected):\n    result = validate_email(email)\n    assert result == expected\n```\n\n### Multiple Parameters\n\n```python\n@pytest.mark.parametrize(\"name,age,valid\", [\n    (\"Alice\", 25, True),\n    (\"Bob\", 17, False),\n    (\"\", 25, False),\n    (\"Charlie\", -1, False),\n])\ndef test_user_validation(name, age, valid):\n    result = validate_user(name, age)\n    assert result == valid\n```\n\n### Parametrize with IDs\n\n```python\n@pytest.mark.parametrize(\"input,expected\", [\n    (\"hello\", \"HELLO\"),\n    (\"world\", \"WORLD\"),\n], ids=[\"lowercase\", \"another_lowercase\"])\ndef test_uppercase(input, expected):\n    assert input.upper() == expected\n```\n\n## Test Markers\n\nUse markers for test categorization and selective execution:\n\n```python\nimport pytest\n\n@pytest.mark.unit\ndef test_calculate_total():\n    \"\"\"Fast unit test\"\"\"\n    assert calculate_total([1, 2, 3]) == 6\n\n@pytest.mark.integration\ndef test_database_connection():\n    \"\"\"Slower integration test\"\"\"\n    db = Database()\n    assert db.connect() is True\n\n@pytest.mark.slow\ndef test_large_dataset():\n    \"\"\"Very slow test\"\"\"\n    process_million_records()\n\n@pytest.mark.skip(reason=\"Not implemented yet\")\ndef test_future_feature():\n    pass\n\n@pytest.mark.skipif(sys.version_info \u003C (3, 10), reason=\"Requires Python 3.10+\")\ndef test_new_syntax():\n    pass\n```\n\n**Run specific markers:**\n```bash\npytest -m unit              # Run only unit tests\npytest -m \"not slow\"        # Skip slow tests\npytest -m \"unit or integration\"  # Run unit OR integration\n```\n\n## Mocking\n\n### Using unittest.mock\n\n```python\nfrom unittest.mock import Mock, patch, MagicMock\n\ndef test_user_service_with_mock():\n    \"\"\"Test with mock repository\"\"\"\n    mock_repo = Mock()\n    mock_repo.find_by_id.return_value = User(id=\"1\", name=\"Alice\")\n\n    service = UserService(mock_repo)\n    user = service.get_user(\"1\")\n\n    assert user.name == \"Alice\"\n    mock_repo.find_by_id.assert_called_once_with(\"1\")\n\n@patch('myapp.services.EmailService')\ndef test_send_notification(mock_email_service):\n    \"\"\"Test with patched dependency\"\"\"\n    service = NotificationService()\n    service.send(\"user@example.com\", \"Hello\")\n\n    mock_email_service.send.assert_called_once()\n```\n\n### pytest-mock Plugin\n\n```python\ndef test_with_mocker(mocker):\n    \"\"\"Using pytest-mock plugin\"\"\"\n    mock_repo = mocker.Mock()\n    mock_repo.find_by_id.return_value = User(id=\"1\", name=\"Alice\")\n\n    service = UserService(mock_repo)\n    user = service.get_user(\"1\")\n\n    assert user.name == \"Alice\"\n```\n\n## Coverage Analysis\n\n### Basic Coverage\n\n```bash\npytest --cov=src --cov-report=term-missing\n```\n\n### HTML Coverage Report\n\n```bash\npytest --cov=src --cov-report=html\nopen htmlcov\u002Findex.html\n```\n\n### Coverage Configuration\n\n```ini\n# pytest.ini or pyproject.toml\n[tool.pytest.ini_options]\naddopts = \"\"\"\n    --cov=src\n    --cov-report=term-missing\n    --cov-report=html\n    --cov-fail-under=80\n\"\"\"\n```\n\n### Branch Coverage\n\n```bash\npytest --cov=src --cov-branch\n```\n\n## Async Testing\n\n### Testing Async Functions\n\n```python\nimport pytest\n\n@pytest.mark.asyncio\nasync def test_async_fetch_user():\n    \"\"\"Test async function\"\"\"\n    user = await fetch_user(\"1\")\n    assert user.name == \"Alice\"\n\n@pytest.fixture\nasync def async_client():\n    \"\"\"Async fixture\"\"\"\n    client = AsyncClient()\n    await client.connect()\n    yield client\n    await client.disconnect()\n\n@pytest.mark.asyncio\nasync def test_with_async_fixture(async_client):\n    result = await async_client.get(\"\u002Fusers\u002F1\")\n    assert result.status == 200\n```\n\n## Test Organization\n\n### Directory Structure\n\n```\ntests\u002F\n├── unit\u002F\n│   ├── test_models.py\n│   ├── test_services.py\n│   └── test_utils.py\n├── integration\u002F\n│   ├── test_database.py\n│   └── test_api.py\n├── conftest.py          # Shared fixtures\n└── pytest.ini           # Configuration\n```\n\n### conftest.py\n\n```python\n# tests\u002Fconftest.py\nimport pytest\n\n@pytest.fixture(scope=\"session\")\ndef app():\n    \"\"\"Application fixture available to all tests\"\"\"\n    return create_app()\n\n@pytest.fixture\ndef client(app):\n    \"\"\"Test client fixture\"\"\"\n    return app.test_client()\n\ndef pytest_configure(config):\n    \"\"\"Register custom markers\"\"\"\n    config.addinivalue_line(\"markers\", \"unit: Unit tests\")\n    config.addinivalue_line(\"markers\", \"integration: Integration tests\")\n    config.addinivalue_line(\"markers\", \"slow: Slow tests\")\n```\n\n## Assertions\n\n### Basic Assertions\n\n```python\ndef test_assertions():\n    assert value == expected\n    assert value != other\n    assert value > 0\n    assert value in collection\n    assert isinstance(value, str)\n```\n\n### pytest Assertions with Better Error Messages\n\n```python\ndef test_with_context():\n    \"\"\"pytest provides detailed assertion introspection\"\"\"\n    result = calculate_total([1, 2, 3])\n    expected = 6\n\n    # pytest shows: assert 5 == 6\n    assert result == expected\n```\n\n### Custom Assertion Messages\n\n```python\ndef test_with_message():\n    result = process_data(input_data)\n    assert result.is_valid, f\"Expected valid result, got errors: {result.errors}\"\n```\n\n### Approximate Comparisons\n\n```python\nimport pytest\n\ndef test_float_comparison():\n    result = 0.1 + 0.2\n    assert result == pytest.approx(0.3)\n\n    # With tolerance\n    assert result == pytest.approx(0.3, abs=1e-9)\n```\n\n## Exception Testing\n\n```python\nimport pytest\n\ndef test_raises_exception():\n    \"\"\"Test that function raises expected exception\"\"\"\n    with pytest.raises(ValueError):\n        validate_age(-1)\n\ndef test_exception_message():\n    \"\"\"Test exception message\"\"\"\n    with pytest.raises(ValueError, match=\"Age must be positive\"):\n        validate_age(-1)\n\ndef test_exception_details():\n    \"\"\"Capture and inspect exception\"\"\"\n    with pytest.raises(ValidationError) as exc_info:\n        validate_user(name=\"\", age=-1)\n\n    assert \"name\" in exc_info.value.errors\n    assert \"age\" in exc_info.value.errors\n```\n\n## Test Helpers\n\n```python\n# tests\u002Fhelpers.py\ndef assert_user_equal(actual, expected):\n    \"\"\"Custom assertion helper\"\"\"\n    assert actual.id == expected.id\n    assert actual.name == expected.name\n    assert actual.email == expected.email\n\ndef create_test_user(**kwargs):\n    \"\"\"Test data factory\"\"\"\n    defaults = {\n        \"name\": \"Test User\",\n        \"email\": \"test@example.com\",\n        \"age\": 25,\n    }\n    defaults.update(kwargs)\n    return User(**defaults)\n```\n\n## Property-Based Testing\n\nUsing `hypothesis` for property-based testing:\n\n```python\nfrom hypothesis import given, strategies as st\n\n@given(st.integers(), st.integers())\ndef test_addition_commutative(a, b):\n    \"\"\"Test that addition is commutative\"\"\"\n    assert a + b == b + a\n\n@given(st.lists(st.integers()))\ndef test_sort_idempotent(lst):\n    \"\"\"Test that sorting twice gives same result\"\"\"\n    sorted_once = sorted(lst)\n    sorted_twice = sorted(sorted_once)\n    assert sorted_once == sorted_twice\n```\n\n## Best Practices\n\n1. **One assertion per test** (when possible)\n2. **Use descriptive test names** - describe what's being tested\n3. **Arrange-Act-Assert pattern** - clear test structure\n4. **Use fixtures for setup** - avoid duplication\n5. **Mock external dependencies** - keep tests fast and isolated\n6. **Test edge cases** - empty inputs, None, boundaries\n7. **Use parametrize** - test multiple scenarios efficiently\n8. **Keep tests independent** - no shared state between tests\n\n## Running Tests\n\n```bash\n# Run all tests\npytest\n\n# Run specific file\npytest tests\u002Ftest_user.py\n\n# Run specific test\npytest tests\u002Ftest_user.py::test_create_user\n\n# Run with verbose output\npytest -v\n\n# Run with output capture disabled\npytest -s\n\n# Run in parallel (requires pytest-xdist)\npytest -n auto\n\n# Run only failed tests from last run\npytest --lf\n\n# Run failed tests first\npytest --ff\n```\n\n## When to Use This Skill\n\n- Writing new Python tests\n- Improving test coverage\n- Setting up pytest infrastructure\n- Debugging flaky tests\n- Implementing integration tests\n- Testing async Python code\n",{"name":5,"metadata":24,"description":29},{"globs":25,"origin":28},[26,27],"**\u002F*.py","**\u002F*.pyi","ECC","Python testing best practices using pytest including fixtures, parametrization, mocking, coverage analysis, async testing, and test organization. Use when writing or improving Python tests.\n","master","d6ca01da0f24a3b0e26e4a8b7b66cbd25d429f5d",".kiro\u002Fskills\u002Fpython-testing",0,"https:\u002F\u002Fgithub.com\u002FSriramGandhiS\u002FSkills","https:\u002F\u002Fgithub.com\u002FSriramGandhiS","https:\u002F\u002Fsriram.website\u002F","Curious guy who keeps tinkering until something works","2026-05-20 16:21:34",{"source":8,"skillName":5,"commands":40,"prompt":50,"zipAvailable":51},[41,44,47],{"tool":42,"command":43},"npx","npx skills add SriramGandhiS\u002FSkills --skill python-testing",{"tool":45,"command":46},"bunx","bunx skills add SriramGandhiS\u002FSkills --skill python-testing",{"tool":48,"command":49},"pnpm","pnpm dlx skills add SriramGandhiS\u002FSkills --skill python-testing","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FSriramGandhiS\u002FSkills\u002Fblob\u002Fmaster\u002F.kiro\u002Fskills\u002Fpython-testing\u002FSKILL.md",true,[],[54,62,67,73,80,87],{"skillNo":55,"name":56,"nameZh":6,"description":57,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":58,"categories":59,"keywords":60,"publishedAt":61},"01M732609EPJWV13PVTX3GT4TM","webgpu-threejs-tsl","Comprehensive guide for developing WebGPU-enabled Three.js applications using TSL (Three.js Shading Language). Covers WebGPU renderer setup, TSL syntax and node materials, compute shaders, post-processing effects, and WGSL integration. Use this skill when working with Three.js WebGPU, TSL shaders, node materials, or GPU compute in Three.js.","https:\u002F\u002Fgithub.com\u002FSriramGandhiS\u002FSkills\u002Fblob\u002Fmaster\u002Fwebgpu-threejs-tsl\u002Fskills\u002Fwebgpu-threejs-tsl\u002FSKILL.md",[],[],"2026-11-11 15:11:14",{"skillNo":63,"name":56,"nameZh":6,"description":57,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":64,"categories":65,"keywords":66,"publishedAt":61},"01M7325XM47AGWB6K6C4VXKE6B","https:\u002F\u002Fgithub.com\u002FSriramGandhiS\u002FSkills\u002Fblob\u002Fmaster\u002Fwebgpu-threejs-tsl\u002FSKILL.md",[],[],{"skillNo":68,"name":69,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":70,"categories":71,"keywords":72,"publishedAt":61},"01M7325WP6DES69JKC840VMFEP","verification-loop","https:\u002F\u002Fgithub.com\u002FSriramGandhiS\u002FSkills\u002Fblob\u002Fmaster\u002Fweb-assets\u002Fdocs\u002Fzh-TW\u002Fskills\u002Fverification-loop\u002FSKILL.md",[],[],{"skillNo":74,"name":75,"nameZh":6,"description":76,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":77,"categories":78,"keywords":79,"publishedAt":61},"01M7325TFQF1DZTQ6J3WGQQ1VR","tdd-workflow","Use this skill when writing new features, fixing bugs, or refactoring code. Enforces test-driven development with 80%+ coverage including unit, integration, and E2E tests.","https:\u002F\u002Fgithub.com\u002FSriramGandhiS\u002FSkills\u002Fblob\u002Fmaster\u002Fweb-assets\u002Fdocs\u002Fzh-TW\u002Fskills\u002Ftdd-workflow\u002FSKILL.md",[],[],{"skillNo":81,"name":82,"nameZh":6,"description":83,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":84,"categories":85,"keywords":86,"publishedAt":61},"01M7325RGV9AY9PK92D2V8KKPW","strategic-compact","Suggests manual context compaction at logical intervals to preserve context through task phases rather than arbitrary auto-compaction.","https:\u002F\u002Fgithub.com\u002FSriramGandhiS\u002FSkills\u002Fblob\u002Fmaster\u002Fweb-assets\u002Fdocs\u002Fzh-TW\u002Fskills\u002Fstrategic-compact\u002FSKILL.md",[],[],{"skillNo":88,"name":89,"nameZh":6,"description":90,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":91,"categories":92,"keywords":93,"publishedAt":61},"01M7325MZC28SE86E7NMCNEFS4","security-review","Use this skill when adding authentication, handling user input, working with secrets, creating API endpoints, or implementing payment\u002Fsensitive features. Provides comprehensive security checklist and patterns.","https:\u002F\u002Fgithub.com\u002FSriramGandhiS\u002FSkills\u002Fblob\u002Fmaster\u002Fweb-assets\u002Fdocs\u002Fzh-TW\u002Fskills\u002Fsecurity-review\u002FSKILL.md",[],[]]