feat(python): Add wire tests#10760
Merged
aditya-arolkar-swe merged 17 commits intomainfrom Nov 23, 2025
Merged
Conversation
Adds pytest-based wire test generation that validates SDK methods against WireMock. Each test creates a client, makes an API call, and verifies the request was properly sent. - Implements generateServiceTestFile() with autouse fixture for test setup - Generates helper functions for WireMock interaction (reset, verify) - Creates test functions for each endpoint with examples - Adds enable_wire_tests config option to both Python v1 and v2 - Includes seed test fixtures for exhaustive validation 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Wire test files were missing imports for pytest, requests, typing, and the generated client. This was because: - The Python AST only supports "from X import Y" style imports - References with empty modulePath are skipped by the import generator - Simple "import X" statements need to be added as raw code blocks Solution: - Added raw code blocks for pytest and requests imports - Used reference tracking for typing and client imports - Created helper to register references for AST-managed imports All test files now have complete import statements at the top. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
…type issues Fixed mypy errors in wire tests by: - Adding types-requests as dev dependency only when enable_wire_tests is true - Properly typing request_body as Dict[str, Any] to handle nested dicts - Converting JSON boolean 'true/false' to Python 'True/False' in test data - Added jsonToPython() helper to properly convert JSON to Python syntax Implementation: - Plumbed enable_wire_tests flag through Project -> PyProjectToml -> DependenciesBlock - Conditionally adds types-requests = "^2.31.0" only when wire tests are enabled - Fixed formatValue() to handle booleans correctly (True/False not true/false) - Added proper type annotations for all variables 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Fixed two issues in generated wire tests:
1. Import path: Changed from `from seed.exhaustive import SeedExhaustive`
to `from seed import SeedExhaustive` (correct module path)
2. Service access: Now properly navigates service hierarchy
(e.g., `client.endpoints.container.method()` instead of `client.method()`)
Implementation:
- Updated getClientModulePath() to return just [organization] instead of [org, workspace]
- Added service parameter to test generation functions
- Build service path from service.name.fernFilepath.allParts using snake_case
- Construct proper client accessor path: "client.{servicePath}.{methodName}()"
Examples of generated paths:
- Top-level service: client.no_auth.post_with_no_auth()
- Nested service: client.endpoints.container.get_and_return_list_of_primitives()
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Wire tests import and use the requests library to communicate with WireMock's admin API for resetting request journals and verifying request counts. Previously only added types-requests (type stubs), but need the actual library too. Changed: Added `requests = "^2.31.0"` alongside `types-requests = "^2.31.0"` in dev dependencies when enable_wire_tests is true. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Added automatic Docker container management using docker-compose healthchecks and pytest session fixtures. **docker-compose.test.yml**: - Added healthcheck that tests WireMock admin health endpoint - Checks every 2s with 15 retries (30s total wait time) - 5s start period before first health check **conftest.py**: - Session-scoped pytest fixture manages container lifecycle - Uses `docker compose up -d --wait` to wait for healthcheck to pass - Automatically starts WireMock before any tests run - Cleans up container with `docker compose down -v` after all tests complete - Proper error handling with stderr output This eliminates manual polling and ensures WireMock is fully ready before tests begin. Docker handles all the retry logic and timeout management. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
…decorators Fixes wire test generation to properly map request parameters and headers: - Remove @pytest.mark.asyncio decorators from synchronous test functions - Use IR property definitions to map wire names to SDK parameter names (e.g., uuid -> uuid_, base64 -> base_64) - Distinguish between flattened object types and single request parameters - Add header parameter support with proper name conversion (X-TEST-HEADER -> x_test_header) - Use discriminated union visitor pattern for request body types All 49 wire tests now pass. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Contributor
🌱 Seed Test SelectorSelect languages to run seed tests for:
How to use: Click the ⋯ menu above → "Edit" → check the boxes you want → click "Update comment". Tests will run automatically and snapshots will be committed to this PR. |
…e tests Updates the Python seed Dockerfile to use docker:dind base image: - Enables wire tests to spin up WireMock containers via docker compose - Follows same pattern as Go seed Dockerfile - Installs Python 3.12, Poetry, Node.js on Alpine Linux - Starts dockerd in background via entrypoint script 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
570bdfa to
a75fe93
Compare
b8d3f5b to
a75fe93
Compare
aditya-arolkar-swe
approved these changes
Nov 23, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Very initial version of wire tests in python behind a feature flag. Utilizes the wiremock approach to testing. Enabled for the exhaustive no-custom-config feature.
Needs some reworking on how we are utilizing examples.