OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.94k stars 6.59k forks source link

[BUG] Python asyncio tests are not closing API Client #19998

Open AngellusMortis opened 3 weeks ago

AngellusMortis commented 3 weeks ago

Bug Report Checklist

Description
openapi-generator version

7.9.0

OpenAPI declaration file content or url

https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/3_0/petstore.yaml

Generation Details
Steps to reproduce
docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli generate -i https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g python -p library=asyncio -o /local/out/python

python -m venv venv
pip install -r requirements.txt -r test-requirements.txt
pytest

Pytest fill give a warning for each API class similar to the following:

Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7f39496c5160>                                                                                                                                                                                     
Related issues/PRs
Suggest a fix

For any of the TestXXXXXApi test classes, just replace the following:

    async def asyncTearDown(self) -> None:
        pass

with

    async def asyncTearDown(self) -> None:
        await self.api.api_client.close()

(for example for the PetStore API spec, it is test/test_pet_api.py:TestPetApi)

wing328 commented 3 weeks ago

can you please file a PR with the suggested fix when you've time?

AngellusMortis commented 3 weeks ago

No, I cannot. I was not even supposed to make the issue. Sorry, I work for one of those orgs that are super hostile against contributing to open source.