Skip to content

Commit 816e73b

Browse files
committed
Merge branch 'main' into zb-write-copy
2 parents bed5bc1 + 6f38dd7 commit 816e73b

File tree

5 files changed

+54
-35
lines changed

5 files changed

+54
-35
lines changed

docs/source/changelog.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ Changelog
44
Note: in some releases, there are no changes, because we always guarantee
55
releasing in step with fsspec.
66

7+
2025.12.0
8+
---------
9+
10+
* Fix CI when run against rela SGC buckets (#71)
11+
* Run extended rests when env var is set (#712)
12+
* Support py3.14 and drop 3.9 (#709)
13+
* Introduce ExtendedGcsFileSystem for Zonal Bucket gRPC Read Path (#707)
14+
715
2025.10.0
816
---------
917

docs/source/developer.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@ provide appropriate GCSFS_TEST_BUCKET, GCSFS_TEST_VERSIONED_BUCKET
2323
GCSFS_ZONAL_TEST_BUCKET(To use for testing Rapid storage features) and GCSFS_TEST_PROJECT,
2424
as well as setting your default google credentials (or providing them via the fsspec config).
2525

26+
When running tests against a real GCS endpoint, you have two options for test buckets:
27+
28+
- **Provide existing buckets**: If you specify buckets that already exist, the
29+
test suite will manage objects *within* them (creating, modifying, and deleting
30+
objects as needed). The buckets themselves will **not** be deleted upon completion.
31+
**Warning**: The test suite will clear the contents of the bucket at the beginning and end of the
32+
test run, so be sure to use a bucket that does not contain important data.
33+
- **Let the tests create buckets**: If you specify bucket names that do not exist,
34+
the test suite will create them for the test run and automatically delete them
35+
during final cleanup.
36+
2637
.. _fake-gcs-server: https://github.com/fsouza/fake-gcs-server
2738

2839
.. raw:: html

gcsfs/tests/conftest.py

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,15 @@ def factory(**kwargs):
102102

103103
@pytest.fixture(scope="session")
104104
def buckets_to_delete():
105-
"""A set to keep track of buckets created during the test session."""
105+
"""
106+
Provides a session-scoped set to track the names of GCS buckets that are
107+
created by the test suite.
108+
109+
When tests run, they may create new GCS buckets. If these buckets are not
110+
deleted, they will persist after the test run, leading to resource leakage.
111+
This set acts as a registry of buckets that the `final_cleanup` fixture
112+
should remove at the end of the entire test session.
113+
"""
106114
return set()
107115

108116

@@ -113,6 +121,11 @@ def gcs(gcs_factory, buckets_to_delete, populate=True):
113121
# Create the bucket if it doesn't exist, otherwise clean it.
114122
if not gcs.exists(TEST_BUCKET):
115123
gcs.mkdir(TEST_BUCKET)
124+
# By adding the bucket name to this set, we are marking it for
125+
# deletion at the end of the test session. This ensures that if
126+
# the test suite creates the bucket, it will also be responsible
127+
# for deleting it. If the bucket already existed, we assume it's
128+
# managed externally and should not be deleted by the tests.
116129
buckets_to_delete.add(TEST_BUCKET)
117130
else:
118131
try:
@@ -138,41 +151,24 @@ def _cleanup_gcs(gcs):
138151

139152
@pytest.fixture(scope="session", autouse=True)
140153
def final_cleanup(gcs_factory, buckets_to_delete):
141-
"""A session-scoped fixture to delete the test buckets after all tests are run."""
154+
"""
155+
A session-scoped, auto-use fixture that deletes all buckets registered
156+
in the `buckets_to_delete` set after the entire test session is complete.
157+
"""
142158
yield
143159
# This code runs after the entire test session finishes
144-
use_extended_gcs = os.getenv(
145-
"GCSFS_EXPERIMENTAL_ZB_HNS_SUPPORT", "false"
146-
).lower() in (
147-
"true",
148-
"1",
149-
)
150160

151-
if use_extended_gcs:
152-
is_real_gcs = (
153-
os.environ.get("STORAGE_EMULATOR_HOST") == "https://storage.googleapis.com"
154-
)
155-
mock_authentication_manager = (
156-
patch("google.auth.default", return_value=(None, "fake-project"))
157-
if not is_real_gcs
158-
else nullcontext()
159-
)
160-
else:
161-
mock_authentication_manager = nullcontext()
162-
163-
with mock_authentication_manager:
164-
gcs = gcs_factory()
165-
for bucket in buckets_to_delete:
166-
# For real GCS, only delete if created by the test suite.
167-
# For emulators, always delete.
168-
try:
169-
if gcs.exists(bucket):
170-
gcs.rm(bucket, recursive=True)
171-
logging.info(f"Cleaned up bucket: {bucket}")
172-
except Exception as e:
173-
logging.warning(
174-
f"Failed to perform final cleanup for bucket {bucket}: {e}"
175-
)
161+
gcs = gcs_factory()
162+
for bucket in buckets_to_delete:
163+
# The cleanup logic attempts to delete every bucket that was
164+
# added to the set during the session. For real GCS, only delete if
165+
# created by the test suite.
166+
try:
167+
if gcs.exists(bucket):
168+
gcs.rm(bucket, recursive=True)
169+
logging.info(f"Cleaned up bucket: {bucket}")
170+
except Exception as e:
171+
logging.warning(f"Failed to perform final cleanup for bucket {bucket}: {e}")
176172

177173

178174
@pytest.fixture
@@ -219,6 +215,8 @@ def gcs_versioned(gcs_factory, buckets_to_delete):
219215
)
220216

221217
if _VERSIONED_BUCKET_CREATED_BY_TESTS:
218+
# If the versioned bucket was created by the test suite, it's added
219+
# here for cleanup.
222220
buckets_to_delete.add(TEST_VERSIONED_BUCKET)
223221
except ImportError:
224222
pass # test_core_versioned is not being run
@@ -231,6 +229,8 @@ def gcs_versioned(gcs_factory, buckets_to_delete):
231229
except FileNotFoundError:
232230
pass
233231
gcs.mkdir(TEST_VERSIONED_BUCKET, enable_versioning=True)
232+
# When using the emulator, the versioned bucket is always recreated
233+
# and added to the cleanup set.
234234
buckets_to_delete.add(TEST_VERSIONED_BUCKET)
235235
gcs.invalidate_cache()
236236
yield gcs

gcsfs/tests/test_zonal_file.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def test_zonal_file_discard(extended_gcsfs, zonal_write_mocks): # noqa: F841
113113
f.discard()
114114
mock_logger.warning.assert_called_once()
115115
assert (
116-
"Discard is unavailable for Zonal Buckets"
116+
"Discard is not applicable for Zonal Buckets"
117117
in mock_logger.warning.call_args[0][0]
118118
)
119119

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
aiohttp!=4.0.0a0, !=4.0.0a1
22
decorator>4.1.2
3-
fsspec==2025.10.0
3+
fsspec==2025.12.0
44
google-auth>=1.2
55
google-auth-oauthlib
66
google-cloud-storage

0 commit comments

Comments
 (0)