Skip to content

[python] Add mock API tests for service/multiple-services and fix generator duplicate class name bug#10358

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/add-test-case-for-pull-4221
Draft

[python] Add mock API tests for service/multiple-services and fix generator duplicate class name bug#10358
Copilot wants to merge 2 commits intomainfrom
copilot/add-test-case-for-pull-4221

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 13, 2026

Adds Python SDK mock API tests for the service/multiple-services Spector scenario. The spec was previously in SKIP_SPECS due to a Python generator bug where multiple clients sharing operation group names in the same namespace would produce duplicate class definitions — causing the second to silently overwrite the first.

Generator fix: merge duplicate operation group classes

When two clients (e.g. ServiceAClient, ServiceBClient) both have an Operations interface in the same namespace, the generator now merges them into a single class with all operations, rather than emitting two identically-named classes.

Before (broken): _operations.py contained two class Operations: definitions; ServiceA's was overwritten by ServiceB's, so ServiceAClient.operations.op_a() raised AttributeError.

After:

class Operations:
    def op_a(self, **kwargs): ...  # ServiceA's operation
    def op_b(self, **kwargs): ...  # ServiceB's operation

Each client instantiates Operations with its own config (ServiceAClientConfiguration / ServiceBClientConfiguration), so routing and API version remain correct per client.

Changed files:

  • generator/pygen/codegen/serializers/__init__.py — deduplicate operation groups by class name before serialization; merge operations from duplicates into the first group
  • generator/pygen/codegen/serializers/operation_groups_serializer.py — add class_operation_groups parameter for deduped class-definition rendering
  • generator/pygen/codegen/templates/operation_groups_container.py.jinja2 — use class_operation_groups for class definitions; keep full operation_groups for request builder generation

Spec enablement

  • eng/scripts/ci/regenerate-common.ts — remove service/multiple-services from SKIP_SPECS; add emitter config (package-name, namespace)

New tests

Sync + async tests covering all 4 scenarios: ServiceAClient.operations.op_a, ServiceAClient.sub_namespace.sub_op_a, ServiceBClient.operations.op_b, ServiceBClient.sub_namespace.sub_op_b — each verifying both happy path (correct api-version → 204) and rejection (wrong api-versionHttpResponseError).

@microsoft-github-policy-service microsoft-github-policy-service bot added the emitter:client:python Issue for the Python client emitter: @typespec/http-client-python label Apr 13, 2026
Copilot AI changed the title [WIP] Add test case for pull request 4221 [python] Add mock API tests for service/multiple-services and fix generator duplicate class name bug Apr 13, 2026
Copilot AI requested a review from msyyc April 13, 2026 23:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:client:python Issue for the Python client emitter: @typespec/http-client-python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[python] add test case for https://github.com/Azure/typespec-azure/pull/4221

2 participants