Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Feb 10, 2026

Plan: Add test case for XML model with enum

Based on PR #9660 which added ModelWithEnum with a Status enum to the XML payload spec, I added Python test cases.

Tasks:

  • Explore the repository structure and understand the generated code
  • Merge/cherry-pick PR Add XML model with enum property test case #9660 changes (ModelWithEnum model and mockapi implementation)
  • Add test case to test_payload_xml.py for the ModelWithEnum
  • Add async test case to test_payload_xml_async.py for the ModelWithEnum
  • Add chronus changelog entry
  • Format changed files
  • Verify Python syntax and test structure
  • Address PR feedback - use Status.SUCCESS instead of raw string "success"

Summary:

Successfully added test cases for XML model with enum property. The changes include:

  1. Added imports - Added ModelWithEnum and Status to the imports in both sync and async test files
  2. Added sync test - test_model_with_enum in test_payload_xml.py that tests GET and PUT operations with a ModelWithEnum instance using status=Status.SUCCESS
  3. Added async test - test_model_with_enum in test_payload_xml_async.py that mirrors the sync test with async/await
  4. Added changelog - Created chronus changelog entry with changeKind: internal for @typespec/http-client-python
  5. Formatted files - All Python files formatted with black

The tests use the generated Status.SUCCESS enum value instead of the raw string "success", following the established pattern in other enum tests.

Original prompt

This section details on the original issue you should resolve

<issue_title>[http-client-python] Add test case for XML model with enum</issue_title>
<issue_description>Add a test case to https://github.com/microsoft/typespec/blob/main/packages/http-client-python/generator/test/generic_mock_api_tests/test_payload_xml.py for #9660 which added a new test API for an XML payload with an enum.

Also add the equivalent async test to https://github.com/microsoft/typespec/blob/main/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_payload_xml_async.py

NOTE:

  • DO add changelog
  • DO format your changed files before commit</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits February 10, 2026 00:58
Co-authored-by: annatisch <8689453+annatisch@users.noreply.github.com>
Co-authored-by: annatisch <8689453+annatisch@users.noreply.github.com>
@microsoft-github-policy-service microsoft-github-policy-service bot added lib:http-specs For issues/prs related to the @typespec/http-specs package emitter:client:python Issue for the Python client emitter: @typespec/http-client-python labels Feb 10, 2026
Copilot AI changed the title [WIP] Add test case for XML model with enum [http-client-python] Add test cases for XML model with enum property Feb 10, 2026
Copilot AI requested a review from annatisch February 10, 2026 01:03

@pytest.mark.asyncio
async def test_model_with_enum(client: XmlClient):
model = ModelWithEnum(status="success")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use the generated enum rather than the raw string, e.g. status=Status.SUCCESS

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot - can you update the tests to use the enum value rather than the string.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to use Status.SUCCESS in commit 389eefb.



def test_model_with_enum(client: XmlClient):
model = ModelWithEnum(status="success")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use the generated enum rather than the raw string, e.g. status=Status.SUCCESS

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to use Status.SUCCESS in commit 389eefb.

Co-authored-by: annatisch <8689453+annatisch@users.noreply.github.com>
@annatisch
Copy link
Member

@copilot - the test failures indicate that the generated Python models cannot be imported for the tests:

_______ ERROR collecting test/generic_mock_api_tests/test_payload_xml.py _______
ImportError while importing test module '/mnt/vss/_work/1/s/packages/http-client-python/generator/test/generic_mock_api_tests/test_payload_xml.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/opt/hostedtoolcache/Python/3.11.14/x64/lib/python3.11/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
../generic_mock_api_tests/test_payload_xml.py:8: in <module>
    from payload.xml.models import (
E   ImportError: cannot import name 'ModelWithEnum' from 'payload.xml.models' (/mnt/vss/_work/1/s/packages/http-client-python/generator/test/azure/generated/payload-xml/payload/xml/models/__init__.py)

Are you missing a code generation step? Or is there another reason the new XML models aren't generating?

Copy link
Contributor Author

Copilot AI commented Feb 11, 2026

@copilot - the test failures indicate that the generated Python models cannot be imported for the tests:

_______ ERROR collecting test/generic_mock_api_tests/test_payload_xml.py _______

...

I see the import error. The test is trying to import ModelWithEnum and Status from the generated Python code, but these models should be generated from the TypeSpec spec during the regenerate step.

The TypeSpec changes (commit 4ae204d) added the ModelWithEnum model and Status union to packages/http-specs/specs/payload/xml/main.tsp. During CI, the regenerate step should:

  1. Build @typespec/http-specs package (which includes my spec changes)
  2. Run npm run regenerate in http-client-python to generate Python models from all specs in node_modules/@typespec/http-specs

Could you share the full CI log? I want to check if:

  • The http-specs package build succeeded
  • The regenerate step ran and completed without errors
  • If regeneration skipped the payload/xml spec for some reason

Alternatively, if you can confirm the regenerate step ran successfully, there might be an issue with how the Python models are being generated from the extensible union (Status).

@annatisch
Copy link
Member

Copy link
Contributor Author

Copilot AI commented Feb 11, 2026

@copilot here is the full CI log:
https://[dev.azure.com/azure-sdk/29ec6040-b234-4e31-b139-33dc4287b756/_apis/build/builds/5863120/logs/481](https://dev.azure.com/azure-sdk/29ec6040-b234-4e31-b139-33...

I found the issue! The CI log shows that payload/xml was successfully compiled:

tsp compile .../node_modules/@typespec/http-specs/specs/payload/xml/main.tsp ... succeeded

But the tests fail with:

ImportError: cannot import name 'ModelWithEnum' from 'payload.xml.models'

The problem is that the regeneration is reading from node_modules/@typespec/http-specs which contains the OLD version of the specs (before my TypeSpec changes in commit 4ae204d). My local changes to packages/http-specs/specs/payload/xml/main.tsp aren't being picked up because:

  1. http-client-python is excluded from the pnpm workspace
  2. It uses npm and depends on a specific published version: @typespec/http-specs@0.1.0-alpha.32-dev.6
  3. My local http-specs changes haven't been built/linked into http-client-python's node_modules

The fix requires ensuring the locally-modified http-specs is available before regeneration. This might need changes to the CI workflow or build process to link the local packages properly.

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 lib:http-specs For issues/prs related to the @typespec/http-specs package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[http-client-python] Add test case for XML model with enum

2 participants