Skip to content

Commit 6af3ea4

Browse files
authored
Allow s3 testing in face of "ambient" AWS creds (#3947)
1 parent 85890b3 commit 6af3ea4

2 files changed

Lines changed: 19 additions & 4 deletions

File tree

pyproject.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,9 @@ ignore = [
365365
python_version = "3.12"
366366
ignore_missing_imports = true
367367
namespace_packages = false
368-
368+
pretty = true
369+
show_error_code_links = true
370+
show_error_context = true
369371
strict = true
370372
warn_unreachable = true
371373
enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"]
@@ -378,7 +380,6 @@ module = [
378380
"tests.test_config",
379381
"tests.test_store.test_zip",
380382
"tests.test_store.test_local",
381-
"tests.test_store.test_fsspec",
382383
"tests.test_store.test_memory",
383384
"tests.test_codecs.test_codecs",
384385
"tests.test_metadata.*",
@@ -394,6 +395,7 @@ strict = false
394395
# and fix the errors
395396
[[tool.mypy.overrides]]
396397
module = [
398+
"tests.test_store.test_fsspec",
397399
"tests.test_group",
398400
"tests.test_indexing",
399401
"tests.test_properties",

tests/test_store/test_fsspec.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,13 @@ def s3_base() -> Generator[None, None, None]:
8080
def get_boto3_client() -> botocore.client.BaseClient:
8181
# NB: we use the sync botocore client for setup
8282
session = botocore.session.Session()
83-
return session.create_client("s3", endpoint_url=endpoint_url)
83+
84+
# Prevent IllegalLocationConstraintException by explicitly setting region to
85+
# "us-east-1", which does not require configuring LocationConstraint during
86+
# bucket creation. (It is, in fact, forbidden for that region.) Necessary
87+
# in the face of "ambient" AWS configuration in a development environment
88+
# where the default region might be configured differently.
89+
return session.create_client("s3", endpoint_url=endpoint_url, region_name="us-east-1")
8490

8591

8692
@pytest.fixture(autouse=True)
@@ -100,7 +106,14 @@ def s3(s3_base: None) -> Generator[s3fs.S3FileSystem, None, None]:
100106
client = get_boto3_client()
101107
client.create_bucket(Bucket=test_bucket_name, ACL="public-read")
102108
s3fs.S3FileSystem.clear_instance_cache()
103-
s3 = s3fs.S3FileSystem(anon=False, client_kwargs={"endpoint_url": endpoint_url})
109+
s3 = s3fs.S3FileSystem(
110+
anon=False,
111+
client_kwargs={"endpoint_url": endpoint_url},
112+
# Prevent "AssertionError: Session was never entered" from aiobotocore
113+
# at end of test execution. Using clear_instance_cache is insufficient,
114+
# although still necessary.
115+
skip_instance_cache=True,
116+
)
104117
session = sync(s3.set_session())
105118
s3.invalidate_cache()
106119
yield s3

0 commit comments

Comments
 (0)