-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
29 lines (22 loc) · 918 Bytes
/
Copy pathconftest.py
File metadata and controls
29 lines (22 loc) · 918 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"""Root conftest: fixtures shared across all Panakoes services.
Provides a `localstack_available` session-scoped fixture that is True when
`AWS_ENDPOINT_URL` is set and the LocalStack health endpoint responds. Tests
that require real AWS resources should be marked `@pytest.mark.integration`
and guard themselves with `localstack_available`.
"""
import os
import pytest
import urllib.request
def _localstack_healthy(url: str) -> bool:
try:
with urllib.request.urlopen(f"{url}/_localstack/health", timeout=2) as r:
return r.status == 200
except Exception:
return False
@pytest.fixture(scope="session")
def localstack_url() -> str | None:
url = os.getenv("AWS_ENDPOINT_URL", "")
return url if url and _localstack_healthy(url) else None
@pytest.fixture(scope="session")
def localstack_available(localstack_url: str | None) -> bool:
return localstack_url is not None