Skip to content

Commit

Permalink
Use env vars for AWS configuration instead
Browse files Browse the repository at this point in the history
  • Loading branch information
tjohnes committed Jan 24, 2024
1 parent 212a16a commit 16e3dc6
Showing 1 changed file with 17 additions and 22 deletions.
39 changes: 17 additions & 22 deletions tests/ut/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import os
import random
from pathlib import Path

Expand All @@ -14,10 +15,6 @@
logger = logging.getLogger(__name__)


def pytest_addoption(parser: pytest.Parser) -> None:
parser.addoption("--region", default="us-east-1")


def pytest_configure(config: pytest.Config) -> None:
# Avoid overly verbose logging.
logging.getLogger("boto3").setLevel(logging.INFO)
Expand All @@ -28,6 +25,13 @@ def pytest_configure(config: pytest.Config) -> None:

@pytest.fixture(scope="session", autouse=True)
def moto_server() -> MotoServer:
# Refer to http://docs.getmoto.org/en/latest/docs/getting_started.html#example-on-usage
os.environ["AWS_ACCESS_KEY_ID"] = "testing"
os.environ["AWS_SECRET_ACCESS_KEY"] = "testing"
os.environ["AWS_SECURITY_TOKEN"] = "testing"
os.environ["AWS_SESSION_TOKEN"] = "testing"
os.environ["AWS_DEFAULT_REGION"] = "us-east-1"

for i, port in enumerate(random.sample(range(50000, 50500), 100)):
try:
server = MotoServer(ThreadedMotoServer(port=port))
Expand All @@ -43,24 +47,18 @@ def moto_server() -> MotoServer:

@pytest.fixture(scope="session")
def ec2(
request: pytest.FixtureRequest, moto_server: MotoServer,
request: pytest.FixtureRequest,
moto_server: MotoServer,
) -> EC2ServiceResource:
return boto3.resource(
"ec2",
endpoint_url=moto_server.endpoint,
region_name=request.config.getoption("--region"),
)
return boto3.resource("ec2", endpoint_url=moto_server.endpoint)


@pytest.fixture(scope="session")
def iam(
request: pytest.FixtureRequest, moto_server: MotoServer,
request: pytest.FixtureRequest,
moto_server: MotoServer,
) -> IAMServiceResource:
return boto3.resource(
"iam",
endpoint_url=moto_server.endpoint,
region_name=request.config.getoption("--region"),
)
return boto3.resource("iam", endpoint_url=moto_server.endpoint)


@pytest.fixture(scope="session")
Expand All @@ -70,10 +68,7 @@ def this_dir() -> Path:

@pytest.fixture(scope="module")
def eks_client(
request: pytest.FixtureRequest, moto_server: MotoServer,
request: pytest.FixtureRequest,
moto_server: MotoServer,
) -> EKSClient:
return boto3.client(
"eks",
endpoint_url=moto_server.endpoint,
region_name=request.config.getoption("--region"),
)
return boto3.client("eks", endpoint_url=moto_server.endpoint)

0 comments on commit 16e3dc6

Please sign in to comment.