Skip to content

feat(dataflow): test_streaming_process_storage.py - #15025

Open
cbonnie wants to merge 1 commit into
mainfrom
cbonnie-patch-4
Open

cbonnie wants to merge 1 commit into
mainfrom
cbonnie-patch-4

Conversation

@cbonnie

@cbonnie cbonnie commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Add automated test for the Cloud Storage to DataFlow streaming sample.

Description

Bug # http://b/589715201

Checklist

Testing

  • I have tested this change on a live environment and verified it works as intended.

Compliance & Style


Post-Approval Actions

  • Please merge this PR for me once it is approved

Add automated test for the Cloud Storage to DataFlow streaming sample.
@cbonnie
cbonnie requested review from a team as code owners December 3, 2026 15:21
@product-auto-label product-auto-label Bot added the samples Issues that are directly related to samples. label Dec 3, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new test file, test_streaming_process_storage.py, to verify the streaming process storage pipeline using Apache Beam. The feedback suggests refactoring the module-level storage.Client() initialization into a pytest fixture to avoid test discovery failures in environments without active Google Cloud credentials, and updating the test function signature to accept this new fixture.

Comment on lines +36 to +45
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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Initializing storage.Client() at the module level can cause test discovery to fail in environments where active Google Cloud credentials are not configured. It is safer and more idiomatic to define a storage_client fixture and inject it into the bucket_name fixture and the test function.

Suggested change
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)
@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)
References
  1. Maintain consistency in test structures by matching the patterns employed by existing or neighboring tests in the same directory, such as using a try...finally block with a teardown function for resource cleanup.

Comment on lines +83 to +85
def test_streaming_process_storage(bucket_name: str) -> None:
bucket = storage_client.bucket(bucket_name)
bucket.blob("input/sales.csv").upload_from_string(SALES_CSV)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Update the test function signature to accept the storage_client fixture so that it is properly injected and used within the test.

Suggested change
def test_streaming_process_storage(bucket_name: str) -> None:
bucket = storage_client.bucket(bucket_name)
bucket.blob("input/sales.csv").upload_from_string(SALES_CSV)
def test_streaming_process_storage(storage_client: storage.Client, bucket_name: str) -> None:
bucket = storage_client.bucket(bucket_name)
bucket.blob("input/sales.csv").upload_from_string(SALES_CSV)

@iennae iennae changed the title Create test_streaming_process_storage.py feat(dataflow): test_streaming_process_storage.py Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant