/
conftest.py
37 lines (27 loc) 路 987 Bytes
/
conftest.py
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
30
31
32
33
34
35
36
37
import os
import pytest
from moto import mock_aws
from moto.core.models import DEFAULT_ACCOUNT_ID
from moto.ec2.models import ec2_backends
from moto.ssm.models import ssm_backends
@pytest.fixture(scope="session", autouse=True)
def aws_credentials():
"""Mocked AWS Credentials for moto."""
# avoid stale creds causing
# RuntimeError: Credentials were refreshed, but the refreshed credentials are still expired.
if "AWS_CREDENTIAL_EXPIRATION" in os.environ:
del os.environ["AWS_CREDENTIAL_EXPIRATION"]
@pytest.fixture(scope="session")
def _mock_aws():
with mock_aws():
yield
@pytest.fixture
def _mock_ec2(_mock_aws: None):
yield
# reset just the ec2 backend because its quicker than resetting all backends
ec2_backends[DEFAULT_ACCOUNT_ID].reset()
@pytest.fixture
def _mock_ssm(_mock_aws: None):
yield
# reset just the ssm backend because its quicker than resetting all backends
ssm_backends[DEFAULT_ACCOUNT_ID].reset()