Skip to content

Commit f8a07ed

Browse files
authored
fix(minio): update minio client usage and ensure bucket creation in tests (#266)
Minio 7.2 introduced breaking changes by requiring keyword arguments. Add in a fail safe to ensure the bucket exists in case `pytest-databases` can't create the bucket.
1 parent 7cd5c8d commit f8a07ed

File tree

2 files changed

+60
-10
lines changed

2 files changed

+60
-10
lines changed

tests/conftest.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
from __future__ import annotations
22

3+
from collections.abc import Generator
34
from pathlib import Path
5+
from typing import TYPE_CHECKING
46

57
import pytest
8+
from minio import Minio
9+
10+
if TYPE_CHECKING:
11+
from pytest_databases.docker.minio import MinioService
612

713
pytest_plugins = [
814
"pytest_databases.docker.postgres",
@@ -17,6 +23,24 @@
1723
here = Path(__file__).parent
1824

1925

26+
@pytest.fixture(scope="session")
27+
def minio_client(minio_service: MinioService, minio_default_bucket_name: str) -> Generator[Minio, None, None]:
28+
"""Override pytest-databases minio_client to use new minio API with keyword arguments."""
29+
client = Minio(
30+
endpoint=minio_service.endpoint,
31+
access_key=minio_service.access_key,
32+
secret_key=minio_service.secret_key,
33+
secure=minio_service.secure,
34+
)
35+
try:
36+
if not client.bucket_exists(bucket_name=minio_default_bucket_name):
37+
client.make_bucket(bucket_name=minio_default_bucket_name)
38+
except Exception as e:
39+
msg = f"Failed to create bucket {minio_default_bucket_name}"
40+
raise RuntimeError(msg) from e
41+
yield client
42+
43+
2044
def pytest_addoption(parser: pytest.Parser) -> None:
2145
"""Add custom pytest command line options."""
2246
parser.addoption(

tests/integration/test_storage/test_storage_integration.py

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,11 @@ def local_test_setup(tmp_path: Path) -> Path:
4444

4545

4646
@pytest.fixture
47-
def fsspec_s3_backend(minio_service: "MinioService", minio_default_bucket_name: str) -> "ObjectStoreProtocol":
47+
def fsspec_s3_backend(
48+
minio_service: "MinioService", minio_client: Minio, minio_default_bucket_name: str
49+
) -> "ObjectStoreProtocol":
4850
"""Set up FSSpec S3 backend for testing."""
51+
_ = minio_client # Ensures bucket is created
4952
from sqlspec.storage.backends.fsspec import FSSpecBackend
5053

5154
return FSSpecBackend(
@@ -59,8 +62,11 @@ def fsspec_s3_backend(minio_service: "MinioService", minio_default_bucket_name:
5962

6063

6164
@pytest.fixture
62-
def obstore_s3_backend(minio_service: "MinioService", minio_default_bucket_name: str) -> "ObjectStoreProtocol":
65+
def obstore_s3_backend(
66+
minio_service: "MinioService", minio_client: Minio, minio_default_bucket_name: str
67+
) -> "ObjectStoreProtocol":
6368
"""Set up ObStore S3 backend for testing."""
69+
_ = minio_client # Ensures bucket is created
6470
from sqlspec.storage.backends.obstore import ObStoreBackend
6571

6672
s3_uri = f"s3://{minio_default_bucket_name}"
@@ -371,8 +377,11 @@ def test_registry_path_resolution(tmp_path: Path) -> None:
371377

372378
@pytest.mark.xdist_group("storage")
373379
@pytest.mark.skipif(not FSSPEC_INSTALLED, reason="fsspec not installed")
374-
def test_registry_s3_fsspec_resolution(minio_service: "MinioService", minio_default_bucket_name: str) -> None:
380+
def test_registry_s3_fsspec_resolution(
381+
minio_service: "MinioService", minio_client: Minio, minio_default_bucket_name: str
382+
) -> None:
375383
"""Test storage registry S3 resolution with FSSpec backend."""
384+
_ = minio_client # Ensures bucket is created
376385
from sqlspec.storage.backends.fsspec import FSSpecBackend
377386

378387
s3_uri = f"s3://{minio_default_bucket_name}/registry_test/"
@@ -399,9 +408,10 @@ def test_registry_s3_fsspec_resolution(minio_service: "MinioService", minio_defa
399408

400409
@pytest.mark.xdist_group("storage")
401410
def test_registry_alias_registration(
402-
minio_service: "MinioService", minio_default_bucket_name: str, tmp_path: Path
411+
minio_service: "MinioService", minio_client: Minio, minio_default_bucket_name: str, tmp_path: Path
403412
) -> None:
404413
"""Test storage registry alias registration and usage."""
414+
_ = minio_client # Ensures bucket is created
405415
from sqlspec.storage.backends.local import LocalStore
406416
from sqlspec.storage.backends.obstore import ObStoreBackend
407417

@@ -462,8 +472,11 @@ def local_backend(tmp_path: Path) -> "ObjectStoreProtocol":
462472

463473

464474
@pytest.fixture
465-
def fsspec_s3_backend_optional(minio_service: "MinioService", minio_default_bucket_name: str) -> "ObjectStoreProtocol":
475+
def fsspec_s3_backend_optional(
476+
minio_service: "MinioService", minio_client: Minio, minio_default_bucket_name: str
477+
) -> "ObjectStoreProtocol":
466478
"""Create FSSpec S3 backend if available."""
479+
_ = minio_client # Ensures bucket is created
467480
if not FSSPEC_INSTALLED:
468481
pytest.skip("fsspec not installed")
469482

@@ -481,8 +494,11 @@ def fsspec_s3_backend_optional(minio_service: "MinioService", minio_default_buck
481494

482495

483496
@pytest.fixture
484-
def obstore_s3_backend_optional(minio_service: "MinioService", minio_default_bucket_name: str) -> "ObjectStoreProtocol":
497+
def obstore_s3_backend_optional(
498+
minio_service: "MinioService", minio_client: Minio, minio_default_bucket_name: str
499+
) -> "ObjectStoreProtocol":
485500
"""Create ObStore S3 backend if available."""
501+
_ = minio_client # Ensures bucket is created
486502
if not OBSTORE_INSTALLED:
487503
pytest.skip("obstore not installed")
488504

@@ -563,8 +579,11 @@ def test_local_backend_error_handling(tmp_path: Path) -> None:
563579

564580
@pytest.mark.xdist_group("storage")
565581
@pytest.mark.skipif(not FSSPEC_INSTALLED, reason="fsspec not installed")
566-
def test_fsspec_s3_error_handling(minio_service: "MinioService", minio_default_bucket_name: str) -> None:
582+
def test_fsspec_s3_error_handling(
583+
minio_service: "MinioService", minio_client: Minio, minio_default_bucket_name: str
584+
) -> None:
567585
"""Test FSSpec S3 backend error handling."""
586+
_ = minio_client # Ensures bucket is created
568587
from sqlspec.exceptions import FileNotFoundInStorageError
569588
from sqlspec.storage.backends.fsspec import FSSpecBackend
570589

@@ -655,9 +674,10 @@ def test_registry_alias_management(tmp_path: Path) -> None:
655674

656675
@pytest.mark.xdist_group("storage")
657676
def test_registry_backend_fallback_order(
658-
tmp_path: Path, minio_service: "MinioService", minio_default_bucket_name: str
677+
tmp_path: Path, minio_service: "MinioService", minio_client: Minio, minio_default_bucket_name: str
659678
) -> None:
660679
"""Test that registry follows correct backend fallback order."""
680+
_ = minio_client # Ensures bucket is created
661681
from sqlspec.storage.backends.local import LocalStore
662682
from sqlspec.storage.backends.obstore import ObStoreBackend
663683

@@ -727,8 +747,11 @@ def test_local_arrow_operations(tmp_path: Path) -> None:
727747
@pytest.mark.xdist_group("storage")
728748
@pytest.mark.skipif(not FSSPEC_INSTALLED, reason="fsspec not installed")
729749
@pytest.mark.skipif(not PYARROW_INSTALLED, reason="PyArrow not installed")
730-
def test_fsspec_s3_arrow_operations(minio_service: "MinioService", minio_default_bucket_name: str) -> None:
750+
def test_fsspec_s3_arrow_operations(
751+
minio_service: "MinioService", minio_client: Minio, minio_default_bucket_name: str
752+
) -> None:
731753
"""Test FSSpec S3 backend Arrow operations if pyarrow is available."""
754+
_ = minio_client # Ensures bucket is created
732755
from sqlspec.storage.backends.fsspec import FSSpecBackend
733756

734757
backend = FSSpecBackend.from_config({
@@ -848,8 +871,11 @@ def test_local_metadata_operations(tmp_path: Path) -> None:
848871

849872
@pytest.mark.xdist_group("storage")
850873
@pytest.mark.skipif(not FSSPEC_INSTALLED, reason="fsspec not installed")
851-
def test_fsspec_s3_metadata_operations(minio_service: "MinioService", minio_default_bucket_name: str) -> None:
874+
def test_fsspec_s3_metadata_operations(
875+
minio_service: "MinioService", minio_client: Minio, minio_default_bucket_name: str
876+
) -> None:
852877
"""Test FSSpec S3 backend metadata operations."""
878+
_ = minio_client # Ensures bucket is created
853879
from sqlspec.storage.backends.fsspec import FSSpecBackend
854880

855881
backend = FSSpecBackend.from_config({

0 commit comments

Comments
 (0)