|
19 | 19 | from typing import Dict, List |
20 | 20 |
|
21 | 21 | import certifi |
22 | | -import minio |
23 | 22 | import pytest |
24 | 23 | import urllib3 |
25 | 24 | from packaging import version |
@@ -276,33 +275,41 @@ def http_client(): |
276 | 275 |
|
277 | 276 |
|
278 | 277 | @pytest.fixture(scope="session") |
279 | | -def minio_client_bare(s3_creds): |
280 | | - """Initialize MinIO client.""" |
281 | | - return minio.Minio( |
282 | | - endpoint=s3_creds["endpoint"], |
283 | | - access_key=s3_creds["access_key"], |
284 | | - secret_key=s3_creds["secret_key"], |
285 | | - secure=False, |
| 278 | +def s3fs_client(s3_creds): |
| 279 | + """Initialize s3fs filesystem for MinIO.""" |
| 280 | + import s3fs |
| 281 | + |
| 282 | + return s3fs.S3FileSystem( |
| 283 | + endpoint_url=f"http://{s3_creds['endpoint']}", |
| 284 | + key=s3_creds["access_key"], |
| 285 | + secret=s3_creds["secret_key"], |
286 | 286 | ) |
287 | 287 |
|
288 | 288 |
|
289 | 289 | @pytest.fixture(scope="session") |
290 | | -def minio_client(s3_creds, minio_client_bare, teardown=False): |
291 | | - """MinIO client with test bucket created.""" |
292 | | - aws_region = "us-east-1" |
| 290 | +def minio_client(s3_creds, s3fs_client, teardown=False): |
| 291 | + """S3 filesystem with test bucket created (legacy name for compatibility).""" |
| 292 | + bucket = s3_creds["bucket"] |
| 293 | + |
| 294 | + # Create bucket if it doesn't exist |
293 | 295 | try: |
294 | | - minio_client_bare.make_bucket(s3_creds["bucket"], location=aws_region) |
295 | | - except minio.error.S3Error as e: |
296 | | - if e.code != "BucketAlreadyOwnedByYou": |
297 | | - raise e |
| 296 | + s3fs_client.mkdir(bucket) |
| 297 | + except Exception: |
| 298 | + # Bucket may already exist |
| 299 | + pass |
298 | 300 |
|
299 | | - yield minio_client_bare |
| 301 | + yield s3fs_client |
300 | 302 |
|
301 | 303 | if not teardown: |
302 | 304 | return |
303 | | - objs = list(minio_client_bare.list_objects(s3_creds["bucket"], recursive=True)) |
304 | | - objs = [minio_client_bare.remove_object(s3_creds["bucket"], o.object_name.encode("utf-8")) for o in objs] |
305 | | - minio_client_bare.remove_bucket(s3_creds["bucket"]) |
| 305 | + # Clean up objects and bucket |
| 306 | + try: |
| 307 | + files = s3fs_client.ls(bucket, detail=False) |
| 308 | + for f in files: |
| 309 | + s3fs_client.rm(f) |
| 310 | + s3fs_client.rmdir(bucket) |
| 311 | + except Exception: |
| 312 | + pass |
306 | 313 |
|
307 | 314 |
|
308 | 315 | # --- Utility fixtures --- |
|
0 commit comments