Repository navigation
Conversation
Add automated test for the batch sample, batch_process_storage.py.
There was a problem hiding this comment.
Code Review
This pull request adds a new integration test test_batch_process_storage.py to verify the batch_process_storage pipeline using a temporary Google Cloud Storage bucket. The review feedback recommends refactoring the module-level storage.Client() instantiation into a pytest fixture to avoid test collection failures in environments where Google Cloud credentials are not configured.
| storage_client = storage.Client() | ||
|
|
||
|
|
||
| @pytest.fixture(scope="function") | ||
| def bucket_name() -> Iterator[str]: | ||
| bucket = storage_client.create_bucket(f"test-bucket-{uuid.uuid4()}") | ||
| try: | ||
| yield bucket.name | ||
| finally: | ||
| bucket.delete(force=True) | ||
|
|
||
|
|
||
| def test_batch_process_storage(bucket_name: str) -> None: |
There was a problem hiding this comment.
Instantiating storage.Client() at the module level can cause test collection to fail in environments where Google Cloud credentials are not configured (e.g., during local linting or dry-run test execution). It is recommended to define storage_client as a pytest fixture and pass it to the dependent fixtures and tests.
| storage_client = storage.Client() | |
| @pytest.fixture(scope="function") | |
| def bucket_name() -> Iterator[str]: | |
| bucket = storage_client.create_bucket(f"test-bucket-{uuid.uuid4()}") | |
| try: | |
| yield bucket.name | |
| finally: | |
| bucket.delete(force=True) | |
| def test_batch_process_storage(bucket_name: str) -> None: | |
| @pytest.fixture(scope="session") | |
| def storage_client() -> storage.Client: | |
| return storage.Client() | |
| @pytest.fixture(scope="function") | |
| def bucket_name(storage_client: storage.Client) -> Iterator[str]: | |
| bucket = storage_client.create_bucket(f"test-bucket-{uuid.uuid4()}") | |
| try: | |
| yield bucket.name | |
| finally: | |
| bucket.delete(force=True) | |
| def test_batch_process_storage(storage_client: storage.Client, bucket_name: str) -> None: |
Improve test_batch_process_storage.py
Add automated test for the batch sample, batch_process_storage.py.
Description
Bug # http://b/589715201
Checklist
Testing
Compliance & Style
Post-Approval Actions