-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconftest.py
61 lines (45 loc) · 1.72 KB
/
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import os
from typing import Any, Generator
import boto3
import pytest
from _pytest.fixtures import FixtureFunctionMarker
from botocore.client import BaseClient
from pyspark.sql import SparkSession
from moto import mock_aws
from create_spark_session import create_spark_session
from spark_pipeline_framework.register import register
@pytest.fixture(scope="session")
def spark_session(request: Any) -> SparkSession:
return create_spark_session(request)
@pytest.fixture(scope="function")
def aws_credentials() -> None:
"""Mocked AWS Credentials for moto."""
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_REGION"] = "us-east-1"
@pytest.fixture(scope="function")
def ssm_mock(
aws_credentials: FixtureFunctionMarker,
) -> Generator[BaseClient, None, None]:
with mock_aws():
yield boto3.client("ssm", region_name="us-east-1")
@pytest.fixture(scope="function")
def s3_mock(
aws_credentials: FixtureFunctionMarker,
) -> Generator[BaseClient, None, None]:
with mock_aws():
yield boto3.client("s3", region_name="us-east-1")
@pytest.fixture(scope="session", autouse=True)
def run_before_each_test() -> Generator[None, Any, None]:
# This code will run before every test
# print("Setting up something before each test")
# You can do setup operations here
# For example, initializing databases, clearing caches, etc.
print("Setting up before each test")
register()
# Optional: You can yield if you want to do tear down after the test
yield
# Optional teardown code here
print("Cleaning up after each test")