[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M75B5ZDBR8VEEENERNRFZ2Z3":3,"skill-same:01M75B5ZDBR8VEEENERNRFZ2Z3":55},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":18,"linkOnly":19,"markdownContent":20,"markdownBody":21,"frontMatter":22,"refName":23,"commitSha":24,"skillDirectory":25,"forksCount":26,"repositoryHtmlUrl":27,"repositoryHomepageUrl":28,"ownerHtmlUrl":29,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":30,"install":31,"resources":44},"01M75B5ZDBR8VEEENERNRFZ2Z3","python-testing-patterns",null,"Implement comprehensive testing strategies with pytest, fixtures, mocking, and test-driven development. Use when writing Python tests, setting up test suites, or implementing testing best practices.","ruake\u002FAWARE","ruake","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F253885939?v=4","01M75AVBM7FRFTS61RZRNMZB6C","01M75AVBMYHD7500NHVANF1HKM",0,"MIT","https:\u002F\u002Fgithub.com\u002Fruake\u002FAWARE\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fpython-testing-patterns\u002FSKILL.md",[],[],"2026-11-12 13:55:43",false,"---\nname: python-testing-patterns\ndescription: Implement comprehensive testing strategies with pytest, fixtures, mocking, and test-driven development. Use when writing Python tests, setting up test suites, or implementing testing best practices.\n---\n\n# Python Testing Patterns\n\nComprehensive guide to implementing robust testing strategies in Python using pytest, fixtures, mocking, parameterization, and test-driven development practices.\n\n## When to Use This Skill\n\n- Writing unit tests for Python code\n- Setting up test suites and test infrastructure\n- Implementing test-driven development (TDD)\n- Creating integration tests for APIs and services\n- Mocking external dependencies and services\n- Testing async code and concurrent operations\n- Setting up continuous testing in CI\u002FCD\n- Implementing property-based testing\n- Testing database operations\n- Debugging failing tests\n\n## Core Concepts\n\n### 1. Test Types\n\n- **Unit Tests**: Test individual functions\u002Fclasses in isolation\n- **Integration Tests**: Test interaction between components\n- **Functional Tests**: Test complete features end-to-end\n- **Performance Tests**: Measure speed and resource usage\n\n### 2. Test Structure (AAA Pattern)\n\n- **Arrange**: Set up test data and preconditions\n- **Act**: Execute the code under test\n- **Assert**: Verify the results\n\n### 3. Test Coverage\n\n- Measure what code is exercised by tests\n- Identify untested code paths\n- Aim for meaningful coverage, not just high percentages\n\n### 4. Test Isolation\n\n- Tests should be independent\n- No shared state between tests\n- Each test should clean up after itself\n\n## Quick Start\n\n```python\n# test_example.py\ndef add(a, b):\n    return a + b\n\ndef test_add():\n    \"\"\"Basic test example.\"\"\"\n    result = add(2, 3)\n    assert result == 5\n\ndef test_add_negative():\n    \"\"\"Test with negative numbers.\"\"\"\n    assert add(-1, 1) == 0\n\n# Run with: pytest test_example.py\n```\n\n## Detailed patterns and worked examples\n\nDetailed pattern documentation lives in `references\u002Fdetails.md`. Read that file when the navigation tier above is insufficient.\n\n## Testing Best Practices\n\n### Test Organization\n\n```python\n# tests\u002F\n#   __init__.py\n#   conftest.py           # Shared fixtures\n#   test_unit\u002F            # Unit tests\n#     test_models.py\n#     test_utils.py\n#   test_integration\u002F     # Integration tests\n#     test_api.py\n#     test_database.py\n#   test_e2e\u002F            # End-to-end tests\n#     test_workflows.py\n```\n\n### Test Naming Convention\n\nA common pattern: `test_\u003Cunit>_\u003Cscenario>_\u003Cexpected_outcome>`. Adapt to your team's preferences.\n\n```python\n# Pattern: test_\u003Cunit>_\u003Cscenario>_\u003Cexpected>\ndef test_create_user_with_valid_data_returns_user():\n    ...\n\ndef test_create_user_with_duplicate_email_raises_conflict():\n    ...\n\ndef test_get_user_with_unknown_id_returns_none():\n    ...\n\n# Good test names - clear and descriptive\ndef test_user_creation_with_valid_data():\n    \"\"\"Clear name describes what is being tested.\"\"\"\n    pass\n\ndef test_login_fails_with_invalid_password():\n    \"\"\"Name describes expected behavior.\"\"\"\n    pass\n\ndef test_api_returns_404_for_missing_resource():\n    \"\"\"Specific about inputs and expected outcomes.\"\"\"\n    pass\n\n# Bad test names - avoid these\ndef test_1():  # Not descriptive\n    pass\n\ndef test_user():  # Too vague\n    pass\n\ndef test_function():  # Doesn't explain what's tested\n    pass\n```\n\n### Testing Retry Behavior\n\nVerify that retry logic works correctly using mock side effects.\n\n```python\nfrom unittest.mock import Mock\n\ndef test_retries_on_transient_error():\n    \"\"\"Test that service retries on transient failures.\"\"\"\n    client = Mock()\n    # Fail twice, then succeed\n    client.request.side_effect = [\n        ConnectionError(\"Failed\"),\n        ConnectionError(\"Failed\"),\n        {\"status\": \"ok\"},\n    ]\n\n    service = ServiceWithRetry(client, max_retries=3)\n    result = service.fetch()\n\n    assert result == {\"status\": \"ok\"}\n    assert client.request.call_count == 3\n\ndef test_gives_up_after_max_retries():\n    \"\"\"Test that service stops retrying after max attempts.\"\"\"\n    client = Mock()\n    client.request.side_effect = ConnectionError(\"Failed\")\n\n    service = ServiceWithRetry(client, max_retries=3)\n\n    with pytest.raises(ConnectionError):\n        service.fetch()\n\n    assert client.request.call_count == 3\n\ndef test_does_not_retry_on_permanent_error():\n    \"\"\"Test that permanent errors are not retried.\"\"\"\n    client = Mock()\n    client.request.side_effect = ValueError(\"Invalid input\")\n\n    service = ServiceWithRetry(client, max_retries=3)\n\n    with pytest.raises(ValueError):\n        service.fetch()\n\n    # Only called once - no retry for ValueError\n    assert client.request.call_count == 1\n```\n\n### Mocking Time with Freezegun\n\nUse freezegun to control time in tests for predictable time-dependent behavior.\n\n```python\nfrom freezegun import freeze_time\nfrom datetime import datetime, timedelta\n\n@freeze_time(\"2026-01-15 10:00:00\")\ndef test_token_expiry():\n    \"\"\"Test token expires at correct time.\"\"\"\n    token = create_token(expires_in_seconds=3600)\n    assert token.expires_at == datetime(2026, 1, 15, 11, 0, 0)\n\n@freeze_time(\"2026-01-15 10:00:00\")\ndef test_is_expired_returns_false_before_expiry():\n    \"\"\"Test token is not expired when within validity period.\"\"\"\n    token = create_token(expires_in_seconds=3600)\n    assert not token.is_expired()\n\n@freeze_time(\"2026-01-15 12:00:00\")\ndef test_is_expired_returns_true_after_expiry():\n    \"\"\"Test token is expired after validity period.\"\"\"\n    token = Token(expires_at=datetime(2026, 1, 15, 11, 30, 0))\n    assert token.is_expired()\n\ndef test_with_time_travel():\n    \"\"\"Test behavior across time using freeze_time context.\"\"\"\n    with freeze_time(\"2026-01-01\") as frozen_time:\n        item = create_item()\n        assert item.created_at == datetime(2026, 1, 1)\n\n        # Move forward in time\n        frozen_time.move_to(\"2026-01-15\")\n        assert item.age_days == 14\n```\n\n### Test Markers\n\n```python\n# test_markers.py\nimport pytest\n\n@pytest.mark.slow\ndef test_slow_operation():\n    \"\"\"Mark slow tests.\"\"\"\n    import time\n    time.sleep(2)\n\n\n@pytest.mark.integration\ndef test_database_integration():\n    \"\"\"Mark integration tests.\"\"\"\n    pass\n\n\n@pytest.mark.skip(reason=\"Feature not implemented yet\")\ndef test_future_feature():\n    \"\"\"Skip tests temporarily.\"\"\"\n    pass\n\n\n@pytest.mark.skipif(os.name == \"nt\", reason=\"Unix only test\")\ndef test_unix_specific():\n    \"\"\"Conditional skip.\"\"\"\n    pass\n\n\n@pytest.mark.xfail(reason=\"Known bug #123\")\ndef test_known_bug():\n    \"\"\"Mark expected failures.\"\"\"\n    assert False\n\n\n# Run with:\n# pytest -m slow          # Run only slow tests\n# pytest -m \"not slow\"    # Skip slow tests\n# pytest -m integration   # Run integration tests\n```\n\n### Coverage Reporting\n\n```bash\n# Install coverage\npip install pytest-cov\n\n# Run tests with coverage\npytest --cov=myapp tests\u002F\n\n# Generate HTML report\npytest --cov=myapp --cov-report=html tests\u002F\n\n# Fail if coverage below threshold\npytest --cov=myapp --cov-fail-under=80 tests\u002F\n\n# Show missing lines\npytest --cov=myapp --cov-report=term-missing tests\u002F\n```\n\nFor advanced patterns (async testing, monkeypatching, property-based testing, database testing, CI\u002FCD integration, and configuration), see [references\u002Fadvanced-patterns.md](references\u002Fadvanced-patterns.md)\n","# Python Testing Patterns\n\nComprehensive guide to implementing robust testing strategies in Python using pytest, fixtures, mocking, parameterization, and test-driven development practices.\n\n## When to Use This Skill\n\n- Writing unit tests for Python code\n- Setting up test suites and test infrastructure\n- Implementing test-driven development (TDD)\n- Creating integration tests for APIs and services\n- Mocking external dependencies and services\n- Testing async code and concurrent operations\n- Setting up continuous testing in CI\u002FCD\n- Implementing property-based testing\n- Testing database operations\n- Debugging failing tests\n\n## Core Concepts\n\n### 1. Test Types\n\n- **Unit Tests**: Test individual functions\u002Fclasses in isolation\n- **Integration Tests**: Test interaction between components\n- **Functional Tests**: Test complete features end-to-end\n- **Performance Tests**: Measure speed and resource usage\n\n### 2. Test Structure (AAA Pattern)\n\n- **Arrange**: Set up test data and preconditions\n- **Act**: Execute the code under test\n- **Assert**: Verify the results\n\n### 3. Test Coverage\n\n- Measure what code is exercised by tests\n- Identify untested code paths\n- Aim for meaningful coverage, not just high percentages\n\n### 4. Test Isolation\n\n- Tests should be independent\n- No shared state between tests\n- Each test should clean up after itself\n\n## Quick Start\n\n```python\n# test_example.py\ndef add(a, b):\n    return a + b\n\ndef test_add():\n    \"\"\"Basic test example.\"\"\"\n    result = add(2, 3)\n    assert result == 5\n\ndef test_add_negative():\n    \"\"\"Test with negative numbers.\"\"\"\n    assert add(-1, 1) == 0\n\n# Run with: pytest test_example.py\n```\n\n## Detailed patterns and worked examples\n\nDetailed pattern documentation lives in `references\u002Fdetails.md`. Read that file when the navigation tier above is insufficient.\n\n## Testing Best Practices\n\n### Test Organization\n\n```python\n# tests\u002F\n#   __init__.py\n#   conftest.py           # Shared fixtures\n#   test_unit\u002F            # Unit tests\n#     test_models.py\n#     test_utils.py\n#   test_integration\u002F     # Integration tests\n#     test_api.py\n#     test_database.py\n#   test_e2e\u002F            # End-to-end tests\n#     test_workflows.py\n```\n\n### Test Naming Convention\n\nA common pattern: `test_\u003Cunit>_\u003Cscenario>_\u003Cexpected_outcome>`. Adapt to your team's preferences.\n\n```python\n# Pattern: test_\u003Cunit>_\u003Cscenario>_\u003Cexpected>\ndef test_create_user_with_valid_data_returns_user():\n    ...\n\ndef test_create_user_with_duplicate_email_raises_conflict():\n    ...\n\ndef test_get_user_with_unknown_id_returns_none():\n    ...\n\n# Good test names - clear and descriptive\ndef test_user_creation_with_valid_data():\n    \"\"\"Clear name describes what is being tested.\"\"\"\n    pass\n\ndef test_login_fails_with_invalid_password():\n    \"\"\"Name describes expected behavior.\"\"\"\n    pass\n\ndef test_api_returns_404_for_missing_resource():\n    \"\"\"Specific about inputs and expected outcomes.\"\"\"\n    pass\n\n# Bad test names - avoid these\ndef test_1():  # Not descriptive\n    pass\n\ndef test_user():  # Too vague\n    pass\n\ndef test_function():  # Doesn't explain what's tested\n    pass\n```\n\n### Testing Retry Behavior\n\nVerify that retry logic works correctly using mock side effects.\n\n```python\nfrom unittest.mock import Mock\n\ndef test_retries_on_transient_error():\n    \"\"\"Test that service retries on transient failures.\"\"\"\n    client = Mock()\n    # Fail twice, then succeed\n    client.request.side_effect = [\n        ConnectionError(\"Failed\"),\n        ConnectionError(\"Failed\"),\n        {\"status\": \"ok\"},\n    ]\n\n    service = ServiceWithRetry(client, max_retries=3)\n    result = service.fetch()\n\n    assert result == {\"status\": \"ok\"}\n    assert client.request.call_count == 3\n\ndef test_gives_up_after_max_retries():\n    \"\"\"Test that service stops retrying after max attempts.\"\"\"\n    client = Mock()\n    client.request.side_effect = ConnectionError(\"Failed\")\n\n    service = ServiceWithRetry(client, max_retries=3)\n\n    with pytest.raises(ConnectionError):\n        service.fetch()\n\n    assert client.request.call_count == 3\n\ndef test_does_not_retry_on_permanent_error():\n    \"\"\"Test that permanent errors are not retried.\"\"\"\n    client = Mock()\n    client.request.side_effect = ValueError(\"Invalid input\")\n\n    service = ServiceWithRetry(client, max_retries=3)\n\n    with pytest.raises(ValueError):\n        service.fetch()\n\n    # Only called once - no retry for ValueError\n    assert client.request.call_count == 1\n```\n\n### Mocking Time with Freezegun\n\nUse freezegun to control time in tests for predictable time-dependent behavior.\n\n```python\nfrom freezegun import freeze_time\nfrom datetime import datetime, timedelta\n\n@freeze_time(\"2026-01-15 10:00:00\")\ndef test_token_expiry():\n    \"\"\"Test token expires at correct time.\"\"\"\n    token = create_token(expires_in_seconds=3600)\n    assert token.expires_at == datetime(2026, 1, 15, 11, 0, 0)\n\n@freeze_time(\"2026-01-15 10:00:00\")\ndef test_is_expired_returns_false_before_expiry():\n    \"\"\"Test token is not expired when within validity period.\"\"\"\n    token = create_token(expires_in_seconds=3600)\n    assert not token.is_expired()\n\n@freeze_time(\"2026-01-15 12:00:00\")\ndef test_is_expired_returns_true_after_expiry():\n    \"\"\"Test token is expired after validity period.\"\"\"\n    token = Token(expires_at=datetime(2026, 1, 15, 11, 30, 0))\n    assert token.is_expired()\n\ndef test_with_time_travel():\n    \"\"\"Test behavior across time using freeze_time context.\"\"\"\n    with freeze_time(\"2026-01-01\") as frozen_time:\n        item = create_item()\n        assert item.created_at == datetime(2026, 1, 1)\n\n        # Move forward in time\n        frozen_time.move_to(\"2026-01-15\")\n        assert item.age_days == 14\n```\n\n### Test Markers\n\n```python\n# test_markers.py\nimport pytest\n\n@pytest.mark.slow\ndef test_slow_operation():\n    \"\"\"Mark slow tests.\"\"\"\n    import time\n    time.sleep(2)\n\n\n@pytest.mark.integration\ndef test_database_integration():\n    \"\"\"Mark integration tests.\"\"\"\n    pass\n\n\n@pytest.mark.skip(reason=\"Feature not implemented yet\")\ndef test_future_feature():\n    \"\"\"Skip tests temporarily.\"\"\"\n    pass\n\n\n@pytest.mark.skipif(os.name == \"nt\", reason=\"Unix only test\")\ndef test_unix_specific():\n    \"\"\"Conditional skip.\"\"\"\n    pass\n\n\n@pytest.mark.xfail(reason=\"Known bug #123\")\ndef test_known_bug():\n    \"\"\"Mark expected failures.\"\"\"\n    assert False\n\n\n# Run with:\n# pytest -m slow          # Run only slow tests\n# pytest -m \"not slow\"    # Skip slow tests\n# pytest -m integration   # Run integration tests\n```\n\n### Coverage Reporting\n\n```bash\n# Install coverage\npip install pytest-cov\n\n# Run tests with coverage\npytest --cov=myapp tests\u002F\n\n# Generate HTML report\npytest --cov=myapp --cov-report=html tests\u002F\n\n# Fail if coverage below threshold\npytest --cov=myapp --cov-fail-under=80 tests\u002F\n\n# Show missing lines\npytest --cov=myapp --cov-report=term-missing tests\u002F\n```\n\nFor advanced patterns (async testing, monkeypatching, property-based testing, database testing, CI\u002FCD integration, and configuration), see [references\u002Fadvanced-patterns.md](references\u002Fadvanced-patterns.md)\n",{"name":5,"description":7},"main","6184979e01f673905139589c194eab38198db2f7",".agents\u002Fskills\u002Fpython-testing-patterns",1,"https:\u002F\u002Fgithub.com\u002Fruake\u002FAWARE","https:\u002F\u002Fruake.github.io\u002FAWARE","https:\u002F\u002Fgithub.com\u002Fruake","2026-11-15 04:27:27",{"source":8,"skillName":5,"commands":32,"prompt":42,"zipAvailable":43},[33,36,39],{"tool":34,"command":35},"npx","npx skills add ruake\u002FAWARE --skill python-testing-patterns",{"tool":37,"command":38},"bunx","bunx skills add ruake\u002FAWARE --skill python-testing-patterns",{"tool":40,"command":41},"pnpm","pnpm dlx skills add ruake\u002FAWARE --skill python-testing-patterns","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fruake\u002FAWARE\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fpython-testing-patterns\u002FSKILL.md",true,[45,51],{"path":46,"resourceType":47,"resourceTypeDesc":48,"sizeBytes":49,"sourceHtmlUrl":50},"references\u002Fadvanced-patterns.md","REFERENCE","参考文档",9454,"https:\u002F\u002Fgithub.com\u002Fruake\u002FAWARE\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fpython-testing-patterns\u002Freferences\u002Fadvanced-patterns.md",{"path":52,"resourceType":47,"resourceTypeDesc":48,"sizeBytes":53,"sourceHtmlUrl":54},"references\u002Fdetails.md",9270,"https:\u002F\u002Fgithub.com\u002Fruake\u002FAWARE\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fpython-testing-patterns\u002Freferences\u002Fdetails.md",[56,62,69,76,83,89],{"skillNo":57,"name":58,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":59,"categories":60,"keywords":61,"publishedAt":18},"01M75BPBYT89TEE87CGBDX2KF5","xlsx","https:\u002F\u002Fgithub.com\u002Fruake\u002FAWARE\u002Fblob\u002Fmain\u002F.opencode\u002Fskills\u002Fxlsx\u002FSKILL.md",[],[],{"skillNo":63,"name":64,"nameZh":6,"description":65,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":66,"categories":67,"keywords":68,"publishedAt":18},"01M75BPA000S9MTH5MY7CZNYYQ","writing-plans","Write comprehensive implementation plans assuming the engineer has zero context for our codebase and questionable taste.","https:\u002F\u002Fgithub.com\u002Fruake\u002FAWARE\u002Fblob\u002Fmain\u002F.opencode\u002Fskills\u002Fwriting-plans\u002FSKILL.md",[],[],{"skillNo":70,"name":71,"nameZh":6,"description":72,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":73,"categories":74,"keywords":75,"publishedAt":18},"01M75BP80ETH9GYVRH8A7QPCSG","web-design-guidelines","Review files for compliance with Web Interface Guidelines.","https:\u002F\u002Fgithub.com\u002Fruake\u002FAWARE\u002Fblob\u002Fmain\u002F.opencode\u002Fskills\u002Fweb-design-guidelines\u002FSKILL.md",[],[],{"skillNo":77,"name":78,"nameZh":6,"description":79,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":80,"categories":81,"keywords":82,"publishedAt":18},"01M75BP5XG8SX5Q2WWZB6QRVFT","web-component-design","Build reusable, maintainable UI components using modern frameworks with clean composition patterns and styling approache","https:\u002F\u002Fgithub.com\u002Fruake\u002FAWARE\u002Fblob\u002Fmain\u002F.opencode\u002Fskills\u002Fweb-component-design\u002FSKILL.md",[],[],{"skillNo":84,"name":85,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":86,"categories":87,"keywords":88,"publishedAt":18},"01M75BP4B1FC4V81QR1VB56H1E","web-artifacts-builder","https:\u002F\u002Fgithub.com\u002Fruake\u002FAWARE\u002Fblob\u002Fmain\u002F.opencode\u002Fskills\u002Fweb-artifacts-builder\u002FSKILL.md",[],[],{"skillNo":90,"name":91,"nameZh":6,"description":92,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":93,"categories":94,"keywords":95,"publishedAt":18},"01M75BP1XVRW8WQ2XXAJBAYV2V","vueuse-functions","This skill is a decision-and-implementation guide for VueUse composables in Vue.js \u002F Nuxt projects. It maps requirements","https:\u002F\u002Fgithub.com\u002Fruake\u002FAWARE\u002Fblob\u002Fmain\u002F.opencode\u002Fskills\u002Fvueuse-functions\u002FSKILL.md",[],[]]