Skip to content

Commit 3f8ce9c

Browse files
authored
s3: listen on 0.0.0.0 + fixes to tests (#257)
1 parent fea03d8 commit 3f8ce9c

File tree

8 files changed

+84
-10
lines changed

8 files changed

+84
-10
lines changed

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ jobs:
2121
with:
2222
fetch-depth: 0
2323

24-
- name: Set up Python 3.12
24+
- name: Set up Python 3.14
2525
uses: actions/setup-python@v6
2626
with:
27-
python-version: '3.12'
27+
python-version: '3.14'
2828

2929
- name: Upgrade pip and nox
3030
run: |

.github/workflows/tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ jobs:
2323
fail-fast: false
2424
matrix:
2525
os: [ubuntu-latest, windows-latest, macos-latest]
26-
pyv: ["3.9", "3.10", "3.11", "3.12", "3.13"]
26+
pyv: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
2727
include:
28-
- {os: ubuntu-latest, pyv: "pypy3.10"}
28+
- {os: ubuntu-latest, pyv: "pypy3.11"}
2929

3030
steps:
3131
- name: Check out the repository
@@ -45,7 +45,7 @@ jobs:
4545
nox --version
4646
4747
- name: Lint code
48-
if: matrix.pyv != 'pypy3.10'
48+
if: ${{ !startsWith(matrix.pyv, 'pypy') }}
4949
run: nox -s lint
5050

5151
# https://github.com/iterative/pytest-servers/pull/122

noxfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212

1313
@nox.session(
14-
python=["3.9", "3.10", "3.11", "3.12", "3.13", "pypy3.10"],
14+
python=["3.9", "3.10", "3.11", "3.12", "3.13", "3.14", "pypy3.11"],
1515
)
1616
def tests(session: nox.Session) -> None:
1717
session.install(".[dev]")

pyproject.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,7 @@ ignore = [
140140
"D105", # missing docstring in magic method
141141
"D107", # missing docstring in method
142142
"ANN002", # missing type annotation
143-
"ANN101", # missing type annotation
144143
"ANN204", # missing return type annotation
145-
"PT004", # pytest-missing-fixture-name-underscore
146144
"PLC0415" # top level imports
147145
]
148146
select = ["ALL"]

src/pytest_servers/fixtures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def tmp_local_path(
4747
) -> UPath:
4848
"""Return a temporary path."""
4949
ret = tmp_upath_factory.mktemp()
50-
monkeypatch.chdir(ret)
50+
monkeypatch.chdir(str(ret))
5151
return ret
5252

5353

src/pytest_servers/s3.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ def __init__(
1717

1818
@property
1919
def endpoint_url(self) -> str:
20-
return f"http://{self.ip_address}:{self.port}"
20+
# `0.0.0.0`/`::` are wildcard bind addresses: valid for listening, but not a
21+
# stable client destination. When users bind moto to all interfaces (common
22+
# on Linux CI), advertise localhost so the test process can connect.
23+
host = self.ip_address
24+
if host in {"0.0.0.0", "::", "::0"}: # noqa: S104
25+
host = "127.0.0.1"
26+
return f"http://{host}:{self.port}"
2127

2228
@property
2329
def port(self) -> int:

tests/conftest.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import platform
2+
3+
import pytest
4+
5+
6+
@pytest.fixture(autouse=True)
7+
def _disable_adlfs_memoryview_optimization_on_pypy(
8+
monkeypatch: pytest.MonkeyPatch,
9+
) -> None:
10+
if platform.python_implementation() != "PyPy":
11+
return
12+
13+
# Remove this whole fixture when either:
14+
# - PyPy exposes an iterable `memoryview` compatible with Azure SDK request-body
15+
# checks, or
16+
# - adlfs updates its own support check / stops using `memoryview` for uploads.
17+
#
18+
# This is intentionally a hard failure: it forces us to re-evaluate whether this
19+
# workaround is still needed.
20+
if hasattr(memoryview(b""), "__iter__"):
21+
pytest.fail(
22+
(
23+
"PyPy memoryview now appears iterable; the adlfs/Azure workaround in "
24+
"tests/conftest.py is likely obsolete and should be removed."
25+
),
26+
)
27+
28+
try:
29+
import adlfs.spec
30+
except Exception: # noqa: BLE001
31+
return
32+
33+
azure_blob_file = getattr(adlfs.spec, "AzureBlobFile", None)
34+
if azure_blob_file is None:
35+
return
36+
37+
# If adlfs itself no longer claims memoryview support, then this workaround should
38+
# be unnecessary and must be removed.
39+
try:
40+
if not azure_blob_file._sdk_supports_memoryview_for_writes(None): # noqa: SLF001
41+
pytest.fail(
42+
(
43+
"adlfs no longer reports memoryview support for writes; the PyPy "
44+
"workaround in tests/conftest.py should be removed."
45+
),
46+
)
47+
except Exception: # noqa: BLE001
48+
# If this API shape changes, we also want a visible signal rather than
49+
# silently masking.
50+
pytest.fail(
51+
"adlfs AzureBlobFile._sdk_supports_memoryview_for_writes API changed; "
52+
"re-evaluate/remove the PyPy workaround in tests/conftest.py.",
53+
)
54+
55+
monkeypatch.setattr(
56+
azure_blob_file,
57+
"_sdk_supports_memoryview_for_writes",
58+
lambda *_args, **_kwargs: False,
59+
raising=False,
60+
)

tests/test_s3_endpoint_url.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import pytest
2+
3+
4+
@pytest.fixture(scope="session")
5+
def s3_server_config() -> dict:
6+
return {"ip_address": "0.0.0.0"}
7+
8+
9+
def test_s3_endpoint_url_is_localhost_when_bound_to_wildcard(s3_server):
10+
assert s3_server["endpoint_url"].startswith("http://127.0.0.1:")

0 commit comments

Comments
 (0)