Azure / autorest.python

Extension for AutoRest (https://github.com/Azure/autorest) that generates Python code
MIT License
81 stars 57 forks source link

[test generation] optimize for "api-version" in generated tests #2798

Open msyyc opened 2 months ago

msyyc commented 2 months ago

"api-version" is usually client-level signature so no need to set it in specific: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/datafactory/azure-mgmt-datafactory/generated_tests/test_data_factory_management_operations.py#L25 image

iscai-msft commented 2 months ago

method-level should override client-level though, I'm not sure what this issue is opened for, can you clarify @msyyc? Thanks!

msyyc commented 2 months ago

api_version is already client level signature, so there is no need to set it when call specific method. The expected generated test shall be like:

    @recorded_by_proxy
    def test_list(self, resource_group):
        response = self.client.operations.list()
        result = [r for r in response]
        # please add some check logic here by yourself
        # ...
iscai-msft commented 2 months ago

We still have the ability on the method-level to override the api-version, because let's say we initialize our client with an api-version that works for most methods, but for a specific method, we want to modify the api-version, so this I believe can have method-level overrides

msyyc commented 2 months ago

Of course python permit users to override api-version when call method. In test generation, we don't want to show it since users may copy the generated test to tests folder for live test then it actually only test the specific api-version instead of default api-version if devs forget to update the test cases which brings some risks.

iscai-msft commented 2 months ago

ah I see, ok that makes sense. Thanks for describing @msyyc!