.cursor/skills/qa-httpx-writer/SKILL.md
Generate httpx/requests API tests for Python with async support, session management, and schema validation using pytest.
npx skillsauth add AZANIR/qa-skills qa-httpx-writerInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Write Python API tests using httpx (or requests) from test case specifications and API contracts. Transform structured test cases (from qa-testcase-from-docs, qa-manual-test-designer) and OpenAPI contracts (from qa-api-contract-curator) into executable pytest API tests with async support, session management, response schema validation, and authentication handling.
| Feature | Description |
| ------- | ----------- |
| Async support | httpx.AsyncClient for async tests; httpx.Client for sync |
| Session management | Connection pooling, cookie persistence, header reuse |
| Response validation | Pydantic models, JSON Schema for contract compliance |
| Authentication | Bearer token, API key, OAuth2, Basic Auth, cookies |
| Retry logic | Configurable retries for transient failures |
| Context managers | with httpx.Client() / async with httpx.AsyncClient() |
test_{resource}_api.py with test functions per endpointconftest.py with base_url, client fixtures (sync/async)Use Context7 MCP for httpx documentation when:
| Pattern | Usage |
| ------- | ----- |
| httpx.Client() | Sync client; use as context manager |
| httpx.AsyncClient() | Async client; use with async with |
| response.status_code | Assert HTTP status |
| response.json() | Parse JSON body |
| response.headers | Access response headers |
| client.get(url) / client.post(url) | HTTP methods |
| client.get(url, headers=...) | Custom headers (auth, etc.) |
| Pydantic validation | Model.model_validate(response.json()) |
| pytest fixtures | base_url, client, async_client in conftest |
See references/patterns.md for CRUD, auth, file upload, streaming, async.
base_url, client (sync), async_client (async) fixturesclass TestUsersAPI: with def test_* methods| Type | Usage |
| ---- | ----- |
| Bearer token | headers={"Authorization": f"Bearer {token}"} |
| API key | headers={"X-API-Key": api_key} or params={"api_key": key} |
| OAuth2 | httpx.OAuth2Client or manual token in headers |
| Basic Auth | auth=httpx.BasicAuth(user, password) |
| Cookies | Session cookies via client.cookies or headers={"Cookie": ...} |
test_{resource}_api.py — e.g., test_users_api.py, test_products_api.pytests/ or tests/api/ per project conventionCan do (autonomous):
Cannot do (requires confirmation):
Will not do (out of scope):
pytest)references/patterns.md — CRUD, auth, file upload, streaming, asyncreferences/assertions.md — Status codes, JSON body, headers, Pydantic/JSON Schema validationreferences/config.md — conftest.py, fixtures, environment config, base URLreferences/best-practices.md — Async vs sync, session reuse, schema validation, test isolationtest_{resource}_api.py| Symptom | Likely Cause | Fix |
| ------- | ------------ | --- |
| Connection refused | Wrong base_url or server not running | Verify base_url in conftest; ensure API is up |
| Tests pass individually, fail together | Shared client state or connection pool | Use function-scoped client fixture; avoid session reuse across tests |
| response.json() fails | Non-JSON response (204, HTML error) | Check response.status_code; use response.text for non-JSON |
| Async tests fail | Missing pytest-asyncio | Add @pytest.mark.asyncio; install pytest-asyncio; set asyncio_mode = "auto" |
| Auth not working | Token expired or wrong header | Check Authorization format; ensure token in scope |
| Pydantic validation error | Response shape differs from model | Align model with API contract; use model_validate with strict=False if needed |
| Timeout errors | Slow API or network | Increase timeout in client; add retry for transient failures |
tools
Analyze OpenAPI/Swagger spec (JSON or YAML) against existing test files and generate an HTML coverage report with QA automation tasks. Use when user provides an OpenAPI spec file and wants to know test coverage status.
testing
Universal QA plan generator supporting 10 plan types including test plans, sprint plans, regression plans, release plans, UAT plans, performance plans, migration plans, onboarding plans, and custom plans.
development
Generate consumer-driven contract tests using Pact for JavaScript and Python to verify microservice API compatibility between consumer and provider.
development
Master skill coordinating all QA skills through pipeline modes (full-cycle, docs-only, testcases-only, write-tests, report), formalized handoff chains, scheduler rules, and framework/language selection based on project context.