[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6E2VYQA9W6WY3067SCMFJ37":3,"skill-same:01M6E2VYQA9W6WY3067SCMFJ37":107},{"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":22,"publishedAt":39,"linkOnly":40,"markdownContent":41,"markdownBody":42,"frontMatter":43,"refName":50,"commitSha":51,"skillDirectory":52,"forksCount":13,"repositoryHtmlUrl":53,"repositoryHomepageUrl":54,"ownerHtmlUrl":55,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":56,"install":57,"resources":70},"01M6E2VYQA9W6WY3067SCMFJ37","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.","7dvq6yrkgs-stack\u002Fplaywright","7dvq6yrkgs-stack","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F251638143?v=4","01M6E061J2AMGWYZ6TK7Y8NM74","01M6E061PQCQJGQMPBERMCFN5G",0,"Apache-2.0","https:\u002F\u002Fgithub.com\u002F7dvq6yrkgs-stack\u002Fplaywright\u002Fblob\u002Fmain\u002Fskills\u002Fpython-testing\u002FSKILL.md",[17],{"categoryNo":18,"categoryName":19,"taxonomyType":20,"taxonomyTypeDesc":21},"01JBSEEDCAT000000000000008","测试与质量","SCENARIO","使用场景",[23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38],"testing","python","python testing","writing","test","coverage analysis","best practices","analysis","testing best practices","coverage","use","async","pytest","organization","fixtures","tests","2026-11-10 10:12:30",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":44,"description":49},{"globs":45,"origin":48},[46,47],"**\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","a2e3284ed4488780397ee2f78217366e11470dfb","skills\u002Fpython-testing","https:\u002F\u002Fgithub.com\u002F7dvq6yrkgs-stack\u002Fplaywright","https:\u002F\u002Fplaywright.dev","https:\u002F\u002Fgithub.com\u002F7dvq6yrkgs-stack","2026-04-25 06:04:45",{"source":8,"skillName":5,"commands":58,"prompt":68,"zipAvailable":69},[59,62,65],{"tool":60,"command":61},"npx","npx skills add 7dvq6yrkgs-stack\u002Fplaywright --skill python-testing",{"tool":63,"command":64},"bunx","bunx skills add 7dvq6yrkgs-stack\u002Fplaywright --skill python-testing",{"tool":66,"command":67},"pnpm","pnpm dlx skills add 7dvq6yrkgs-stack\u002Fplaywright --skill python-testing","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002F7dvq6yrkgs-stack\u002Fplaywright\u002Fblob\u002Fmain\u002Fskills\u002Fpython-testing\u002FSKILL.md",true,[71,77,81,85,89,93,99,103],{"path":72,"resourceType":73,"resourceTypeDesc":74,"sizeBytes":75,"sourceHtmlUrl":76},".skillfish.json","REFERENCE","参考文档",241,"https:\u002F\u002Fgithub.com\u002F7dvq6yrkgs-stack\u002Fplaywright\u002Fblob\u002Fmain\u002Fskills\u002Fpython-testing\u002F.skillfish.json",{"path":78,"resourceType":73,"resourceTypeDesc":74,"sizeBytes":79,"sourceHtmlUrl":80},"references\u002Fcomputer_vision_architectures.md",16433,"https:\u002F\u002Fgithub.com\u002Fmarshadgani\u002FArshad.AI\u002Fblob\u002Fclaude\u002Fai-personal-assistant-main\u002F.claude\u002Fskills\u002Fclaude-skills\u002Fsenior-computer-vision\u002Freferences\u002Fcomputer_vision_architectures.md",{"path":82,"resourceType":73,"resourceTypeDesc":74,"sizeBytes":83,"sourceHtmlUrl":84},"references\u002Fobject_detection_optimization.md",22641,"https:\u002F\u002Fgithub.com\u002Fmarshadgani\u002FArshad.AI\u002Fblob\u002Fclaude\u002Fai-personal-assistant-main\u002F.claude\u002Fskills\u002Fclaude-skills\u002Fsenior-computer-vision\u002Freferences\u002Fobject_detection_optimization.md",{"path":86,"resourceType":73,"resourceTypeDesc":74,"sizeBytes":87,"sourceHtmlUrl":88},"references\u002Fproduction_vision_systems.md",34179,"https:\u002F\u002Fgithub.com\u002Fmarshadgani\u002FArshad.AI\u002Fblob\u002Fclaude\u002Fai-personal-assistant-main\u002F.claude\u002Fskills\u002Fclaude-skills\u002Fsenior-computer-vision\u002Freferences\u002Fproduction_vision_systems.md",{"path":90,"resourceType":73,"resourceTypeDesc":74,"sizeBytes":91,"sourceHtmlUrl":92},"references\u002Freference-docs-and-commands.md",2602,"https:\u002F\u002Fgithub.com\u002Fmarshadgani\u002FArshad.AI\u002Fblob\u002Fclaude\u002Fai-personal-assistant-main\u002F.claude\u002Fskills\u002Fclaude-skills\u002Fsenior-computer-vision\u002Freferences\u002Freference-docs-and-commands.md",{"path":94,"resourceType":95,"resourceTypeDesc":96,"sizeBytes":97,"sourceHtmlUrl":98},"scripts\u002Fdataset_pipeline_builder.py","SCRIPT","脚本",65583,"https:\u002F\u002Fgithub.com\u002Fmarshadgani\u002FArshad.AI\u002Fblob\u002Fclaude\u002Fai-personal-assistant-main\u002F.claude\u002Fskills\u002Fclaude-skills\u002Fsenior-computer-vision\u002Fscripts\u002Fdataset_pipeline_builder.py",{"path":100,"resourceType":95,"resourceTypeDesc":96,"sizeBytes":101,"sourceHtmlUrl":102},"scripts\u002Finference_optimizer.py",21386,"https:\u002F\u002Fgithub.com\u002Fmarshadgani\u002FArshad.AI\u002Fblob\u002Fclaude\u002Fai-personal-assistant-main\u002F.claude\u002Fskills\u002Fclaude-skills\u002Fsenior-computer-vision\u002Fscripts\u002Finference_optimizer.py",{"path":104,"resourceType":95,"resourceTypeDesc":96,"sizeBytes":105,"sourceHtmlUrl":106},"scripts\u002Fvision_model_trainer.py",21280,"https:\u002F\u002Fgithub.com\u002Fmarshadgani\u002FArshad.AI\u002Fblob\u002Fclaude\u002Fai-personal-assistant-main\u002F.claude\u002Fskills\u002Fclaude-skills\u002Fsenior-computer-vision\u002Fscripts\u002Fvision_model_trainer.py",[108,138,148,158,173,188],{"skillNo":109,"name":110,"nameZh":6,"description":111,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":112,"categories":113,"keywords":126,"publishedAt":39},"01M6E3XK4PRPMQHM7Y98FQPTY1","zyte-api-automation","Automate Zyte API tasks via Rube MCP (Composio). Always search tools first for current schemas.","https:\u002F\u002Fgithub.com\u002F7dvq6yrkgs-stack\u002Fplaywright\u002Fblob\u002Fmain\u002Fskills\u002Fzyte-api-automation\u002FSKILL.md",[114,115,118,121],{"categoryNo":18,"categoryName":19,"taxonomyType":20,"taxonomyTypeDesc":21},{"categoryNo":116,"categoryName":117,"taxonomyType":20,"taxonomyTypeDesc":21},"01JBSEEDCAT000000000000010","后端与接口",{"categoryNo":119,"categoryName":120,"taxonomyType":20,"taxonomyTypeDesc":21},"01JBSEEDCAT000000000000023","Skill与智能体开发",{"categoryNo":122,"categoryName":123,"taxonomyType":124,"taxonomyTypeDesc":125},"01JBSEEDCAT000000000000030","开发工程师","PROFESSION","适用职业",[127,128,129,130,131,132,133,134,135,136,137],"zyte api automation","api","automation","MCP","tasks","search","Tools","first","automate","composio","via",{"skillNo":139,"name":140,"nameZh":6,"description":141,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":142,"categories":143,"keywords":146,"publishedAt":39},"01M6E3XFX6QSTR1QR59NFXJTMA","zylvie-automation","Automate Zylvie tasks via Rube MCP (Composio). Always search tools first for current schemas.","https:\u002F\u002Fgithub.com\u002F7dvq6yrkgs-stack\u002Fplaywright\u002Fblob\u002Fmain\u002Fskills\u002Fzylvie-automation\u002FSKILL.md",[144,145],{"categoryNo":18,"categoryName":19,"taxonomyType":20,"taxonomyTypeDesc":21},{"categoryNo":119,"categoryName":120,"taxonomyType":20,"taxonomyTypeDesc":21},[147,129,135,130,131,132,133,134,136,137],"zylvie automation",{"skillNo":149,"name":150,"nameZh":6,"description":151,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":152,"categories":153,"keywords":156,"publishedAt":39},"01M6E3XCX2GDYYCHN58ZJHT37M","zoominfo-automation","Automate Zoominfo tasks via Rube MCP (Composio). Always search tools first for current schemas.","https:\u002F\u002Fgithub.com\u002F7dvq6yrkgs-stack\u002Fplaywright\u002Fblob\u002Fmain\u002Fskills\u002Fzoominfo-automation\u002FSKILL.md",[154,155],{"categoryNo":18,"categoryName":19,"taxonomyType":20,"taxonomyTypeDesc":21},{"categoryNo":119,"categoryName":120,"taxonomyType":20,"taxonomyTypeDesc":21},[157,129,132,133,134,135,136,137,131,130],"zoominfo automation",{"skillNo":159,"name":160,"nameZh":6,"description":161,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":162,"categories":163,"keywords":166,"publishedAt":39},"01M6E3X9WJ2T73216WQHHTB9BD","zoho_mail-automation","Automate Zoho Mail tasks via Rube MCP (Composio): email sending, folders, labels, and mailbox management. Always search tools first for current schemas.","https:\u002F\u002Fgithub.com\u002F7dvq6yrkgs-stack\u002Fplaywright\u002Fblob\u002Fmain\u002Fskills\u002Fzoho_mail-automation\u002FSKILL.md",[164,165],{"categoryNo":18,"categoryName":19,"taxonomyType":20,"taxonomyTypeDesc":21},{"categoryNo":119,"categoryName":120,"taxonomyType":20,"taxonomyTypeDesc":21},[167,168,169,129,130,131,132,170,133,134,135,171,136,172,137],"mail","zoho mail automation","zoho","email","management","mailbox",{"skillNo":174,"name":175,"nameZh":6,"description":176,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":177,"categories":178,"keywords":184,"publishedAt":39},"01M6E3X719W648XZBW1EC6JQ64","zoho_invoice-automation","Automate Zoho Invoice tasks via Rube MCP (Composio): invoices, estimates, expenses, clients, and payment tracking. Always search tools first for current schemas.","https:\u002F\u002Fgithub.com\u002F7dvq6yrkgs-stack\u002Fplaywright\u002Fblob\u002Fmain\u002Fskills\u002Fzoho_invoice-automation\u002FSKILL.md",[179,180,181],{"categoryNo":18,"categoryName":19,"taxonomyType":20,"taxonomyTypeDesc":21},{"categoryNo":119,"categoryName":120,"taxonomyType":20,"taxonomyTypeDesc":21},{"categoryNo":182,"categoryName":183,"taxonomyType":124,"taxonomyTypeDesc":125},"01JBSEEDCAT000000000000040","财务",[185,169,129,131,132,133,134,135,186,187,136,137,130],"zoho invoice automation","tracking","payment",{"skillNo":189,"name":190,"nameZh":6,"description":191,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":192,"categories":193,"keywords":196,"publishedAt":39},"01M6E3X28JYTC3QTK32AQF7BYB","zoho_inventory-automation","Automate Zoho Inventory tasks via Rube MCP (Composio): items, orders, warehouses, shipments, and stock management. Always search tools first for current schemas.","https:\u002F\u002Fgithub.com\u002F7dvq6yrkgs-stack\u002Fplaywright\u002Fblob\u002Fmain\u002Fskills\u002Fzoho_inventory-automation\u002FSKILL.md",[194,195],{"categoryNo":18,"categoryName":19,"taxonomyType":20,"taxonomyTypeDesc":21},{"categoryNo":119,"categoryName":120,"taxonomyType":20,"taxonomyTypeDesc":21},[129,197,169,198,134,135,133,132,131,130,136,137,199,200,171],"inventory","zoho inventory automation","stock","orders"]