gapic-generator-python icon indicating copy to clipboard operation
gapic-generator-python copied to clipboard

Remove unused imports in generated test code

Open parthea opened this issue 2 years ago • 0 comments

Unused imports should be removed from generated test code. This may be fixed automatically if we add static analysis (mypy) checks on the tests directory.

Currently we're only running mypy on the client code and not the test code. https://github.com/googleapis/gapic-generator-python/blob/ecf4bb0bae89c87afa5bb3c6dd307793a4e7e80b/tests/integration/goldens/credentials/noxfile.py#L94-L98

In addition, some of the code has # type: ignore directives which bypass static analysis.

from google.cloud.gkehub.configmanagement.v1 import configmanagement_pb2  # type: ignore
from google.cloud.gkehub.multiclusteringress.v1 import multiclusteringress_pb2  # type: ignore

In order for the issue to be caught by static analysis we need to remove the # type: ignore which is bypassing checks.

As an example, see the code in test_gke_hub.py for google/cloud/gkehub/v1 where configmanagement_pb2 and multiclusteringress_pb2 are unused.

https://github.com/googleapis/googleapis-gen/blob/2015275a7dda2ad3d1609f06c4208125c7de8a9d/google/cloud/gkehub/v1/gkehub-v1-py/tests/unit/gapic/gkehub_v1/test_gke_hub.py#L50

parthea avatar Oct 30 '23 15:10 parthea