2222@pytest .fixture
2323def gcs_buffer (monkeypatch ):
2424 """Emulate GCS using a binary buffer."""
25- from fsspec import (
26- AbstractFileSystem ,
27- registry ,
28- )
29-
30- registry .target .clear () # remove state
25+ import fsspec
3126
3227 gcs_buffer = BytesIO ()
3328 gcs_buffer .close = lambda : True
3429
35- class MockGCSFileSystem (AbstractFileSystem ):
30+ class MockGCSFileSystem (fsspec . AbstractFileSystem ):
3631 def open (* args , ** kwargs ):
3732 gcs_buffer .seek (0 )
3833 return gcs_buffer
@@ -41,7 +36,8 @@ def ls(self, path, **kwargs):
4136 # needed for pyarrow
4237 return [{"name" : path , "type" : "file" }]
4338
44- monkeypatch .setattr ("gcsfs.GCSFileSystem" , MockGCSFileSystem )
39+ # Overwrites the default implementation from gcsfs to our mock class
40+ fsspec .register_implementation ("gs" , MockGCSFileSystem , clobber = True )
4541
4642 return gcs_buffer
4743
@@ -54,9 +50,6 @@ def test_to_read_gcs(gcs_buffer, format):
5450
5551 GH 33987
5652 """
57- from fsspec import registry
58-
59- registry .target .clear () # remove state
6053
6154 df1 = DataFrame (
6255 {
@@ -131,9 +124,6 @@ def test_to_csv_compression_encoding_gcs(gcs_buffer, compression_only, encoding)
131124 GH 35677 (to_csv, compression), GH 26124 (to_csv, encoding), and
132125 GH 32392 (read_csv, encoding)
133126 """
134- from fsspec import registry
135-
136- registry .target .clear () # remove state
137127 df = tm .makeDataFrame ()
138128
139129 # reference of compressed and encoded file
@@ -173,12 +163,8 @@ def test_to_csv_compression_encoding_gcs(gcs_buffer, compression_only, encoding)
173163@td .skip_if_no ("gcsfs" )
174164def test_to_parquet_gcs_new_file (monkeypatch , tmpdir ):
175165 """Regression test for writing to a not-yet-existent GCS Parquet file."""
176- from fsspec import (
177- AbstractFileSystem ,
178- registry ,
179- )
166+ from fsspec import AbstractFileSystem
180167
181- registry .target .clear () # remove state
182168 df1 = DataFrame (
183169 {
184170 "int" : [1 , 3 ],
0 commit comments