[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7BEYC28VDE05SYX718T0P05":3,"skill-same:01M7BEYC28VDE05SYX718T0P05":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":35,"ownerHtmlUrl":36,"ownerBlogUrl":6,"ownerDescription":37,"updatedAt":38,"install":39,"resources":52},"01M7BEYC28VDE05SYX718T0P05","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.","YYC-Cube\u002FYYC3-Knowledge-Base","YYC-Cube","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F235006543?v=4","01M79J2PH4SWD2X0825X6PN748","yyc3","01M79J2PHVK3F6ZBYT8K2SCZCW",1,"MIT","https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base\u002Fblob\u002Fmain\u002FYYC3-AI-应用工具\u002FYYC3-AI-应用工具-Everything-claude-code\u002F.kiro\u002Fskills\u002Fpython-testing\u002FSKILL.md",[],[],"2026-11-15 14:19:17",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","main","87afe6ce96220accf50a345dea46784c8c9f210e","YYC3-AI-应用工具\u002FYYC3-AI-应用工具-Everything-claude-code\u002F.kiro\u002Fskills\u002Fpython-testing",0,"https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base","https:\u002F\u002Fkb.yyc3.top\u002F","https:\u002F\u002Fgithub.com\u002FYYC-Cube","万象归元于云枢 | 深栈智启新纪元","2026-11-10 10:37:32",{"source":8,"skillName":5,"commands":40,"prompt":50,"zipAvailable":51},[41,44,47],{"tool":42,"command":43},"npx","npx skills add YYC-Cube\u002FYYC3-Knowledge-Base --skill python-testing",{"tool":45,"command":46},"bunx","bunx skills add YYC-Cube\u002FYYC3-Knowledge-Base --skill python-testing",{"tool":48,"command":49},"pnpm","pnpm dlx skills add YYC-Cube\u002FYYC3-Knowledge-Base --skill python-testing","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base\u002Fblob\u002Fmain\u002FYYC3-AI-应用工具\u002FYYC3-AI-应用工具-Everything-claude-code\u002F.kiro\u002Fskills\u002Fpython-testing\u002FSKILL.md",true,[],[54,61,68,75,82,89],{"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":19},"01M7CTDWHERCXPQCP0K03A86AS","vercel-sandbox","Run agent-browser + Chrome inside Vercel Sandbox microVMs for browser automation from any Vercel-deployed app. Use when the user needs browser automation in a Vercel app (Next.js, SvelteKit, Nuxt, Remix, Astro, etc.), wants to run headless Chrome without binary size limits, needs persistent browser sessions across commands, or wants ephemeral isolated browser environments. Triggers include \"Vercel Sandbox browser\", \"microVM Chrome\", \"agent-browser in sandbox\", \"browser automation on Vercel\", or any task requiring Chrome in a Vercel Sandbox.","https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base\u002Fblob\u002Fmain\u002FYYC3-WebSpec-Web标准\u002FYYC3-WebSpec-Web标准-standards\u002Fbrowser-agent\u002Fskills\u002Fvercel-sandbox\u002FSKILL.md",[],[],{"skillNo":62,"name":63,"nameZh":6,"description":64,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":65,"categories":66,"keywords":67,"publishedAt":19},"01M7CTD8D2BNJY54S65M47HEJA","slack","Interact with Slack workspaces using browser automation. Use when the user needs to check unread channels, navigate Slack, send messages, extract data, find information, search conversations, or automate any Slack task. Triggers include \"check my Slack\", \"what channels have unreads\", \"send a message to\", \"search Slack for\", \"extract from Slack\", \"find who said\", or any task requiring programmatic Slack interaction.","https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base\u002Fblob\u002Fmain\u002FYYC3-WebSpec-Web标准\u002FYYC3-WebSpec-Web标准-standards\u002Fbrowser-agent\u002Fskills\u002Fslack\u002FSKILL.md",[],[],{"skillNo":69,"name":70,"nameZh":6,"description":71,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":72,"categories":73,"keywords":74,"publishedAt":19},"01M7CTCSSB8ZP3Q58C3YZDZK1W","electron","Automate Electron desktop apps (VS Code, Slack, Discord, Figma, Notion, Spotify, etc.) using agent-browser via Chrome DevTools Protocol. Use when the user needs to interact with an Electron app, automate a desktop app, connect to a running app, control a native app, or test an Electron application. Triggers include \"automate Slack app\", \"control VS Code\", \"interact with Discord app\", \"test this Electron app\", \"connect to desktop app\", or any task requiring automation of a native Electron application.","https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base\u002Fblob\u002Fmain\u002FYYC3-WebSpec-Web标准\u002FYYC3-WebSpec-Web标准-standards\u002Fbrowser-agent\u002Fskills\u002Felectron\u002FSKILL.md",[],[],{"skillNo":76,"name":77,"nameZh":6,"description":78,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":79,"categories":80,"keywords":81,"publishedAt":19},"01M7CTCBJY76688V4DCZGWFHGQ","dogfood","Systematically explore and test a web application to find bugs, UX issues, and other problems. Use when asked to \"dogfood\", \"QA\", \"exploratory test\", \"find issues\", \"bug hunt\", \"test this app\u002Fsite\u002Fplatform\", or review the quality of a web application. Produces a structured report with full reproduction evidence -- step-by-step screenshots, repro videos, and detailed repro steps for every issue -- so findings can be handed directly to the responsible teams.","https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base\u002Fblob\u002Fmain\u002FYYC3-WebSpec-Web标准\u002FYYC3-WebSpec-Web标准-standards\u002Fbrowser-agent\u002Fskills\u002Fdogfood\u002FSKILL.md",[],[],{"skillNo":83,"name":84,"nameZh":6,"description":85,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":86,"categories":87,"keywords":88,"publishedAt":19},"01M7CTC4H0FFGVEAQR9PA4GA1A","agent-browser","Browser automation CLI for AI agents. Use when the user needs to interact with websites, including navigating pages, filling forms, clicking buttons, taking screenshots, extracting data, testing web apps, or automating any browser task. Triggers include requests to \"open a website\", \"fill out a form\", \"click a button\", \"take a screenshot\", \"scrape data from a page\", \"test this web app\", \"login to a site\", \"automate browser actions\", or any task requiring programmatic web interaction.","https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base\u002Fblob\u002Fmain\u002FYYC3-WebSpec-Web标准\u002FYYC3-WebSpec-Web标准-standards\u002Fbrowser-agent\u002Fskills\u002Fagent-browser\u002FSKILL.md",[],[],{"skillNo":90,"name":91,"nameZh":6,"description":92,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":93,"categories":94,"keywords":95,"publishedAt":19},"01M7CTBKVFYBG78FDSABSDJTTQ","shadcn","Manages shadcn components and projects — adding, searching, fixing, debugging, styling, and composing UI, including chat interfaces. Provides project context, component docs, and usage examples. Applies when working with shadcn\u002Fui, component registries, presets, --preset codes, or any project with a components.json file. Also triggers for \"shadcn init\", \"create an app with --preset\", \"switch to --preset\", and for building a design system or applying a DESIGN.md or brand spec to shadcn\u002Fui.","https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base\u002Fblob\u002Fmain\u002FYYC3-UI-界面组件\u002FYYC3-UI-界面组件-ui\u002Fskills\u002Fshadcn\u002FSKILL.md",[],[]]