Skip to content

Commit 4f3b99e

Browse files
committed
fix tests
1 parent b4d164f commit 4f3b99e

File tree

2 files changed

+40
-27
lines changed

2 files changed

+40
-27
lines changed

gooddata-pipelines/tests/backup_and_restore/test_backup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def backup_manager(mock_logger):
6060

6161

6262
@pytest.fixture()
63-
def s3(aws_credentials):
63+
def s3():
6464
with mock_aws():
6565
yield boto3.resource("s3")
6666

@@ -274,7 +274,7 @@ def test_local_storage_export(backup_manager):
274274
shutil.rmtree("tests/data/local_export")
275275

276276

277-
def test_file_upload(backup_manager, s3, s3_bucket, mock_boto_session):
277+
def test_file_upload(backup_manager, s3, s3_bucket):
278278
backup_manager.storage.export("tests/data/backup/test_exports", "services")
279279
s3.Object(
280280
S3_BUCKET,

gooddata-pipelines/tests/conftest.py

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,51 @@
11
# (C) 2025 GoodData Corporation
2-
import os
3-
from typing import Generator
2+
3+
from unittest.mock import Mock
44

55
import boto3
66
import pytest
7+
from moto import mock_aws
78

89
from gooddata_pipelines.api import GoodDataApi
910

1011

11-
@pytest.fixture(scope="session", autouse=True)
12-
def aws_credentials() -> Generator[None, None, None]:
13-
"""
14-
Set dummy AWS credentials for the entire test session.
15-
This is an autouse fixture, so it runs automatically.
16-
"""
17-
os.environ["AWS_ACCESS_KEY_ID"] = "testing"
18-
os.environ["AWS_SECRET_ACCESS_KEY"] = "testing"
19-
os.environ["AWS_SECURITY_TOKEN"] = "testing"
20-
os.environ["AWS_SESSION_TOKEN"] = "testing"
21-
os.environ["AWS_DEFAULT_REGION"] = "us-east-1"
22-
yield
12+
@pytest.fixture(scope="function", autouse=True)
13+
def mock_aws_services():
14+
"""Mock AWS services for each test"""
15+
with mock_aws():
16+
yield
2317

2418

25-
@pytest.fixture
26-
def mock_boto_session(mocker):
27-
"""
28-
Mocks boto3.Session to prevent it from using a real AWS profile.
29-
It will return a default Session object, which then uses the
30-
dummy credentials set by the conftest.py fixture.
31-
"""
32-
# We patch boto3.Session and make it return a new, default session object.
33-
# This new object will not have the `profile_name` and will fall back
34-
# to using the environment variables we set in conftest.
35-
mocker.patch("boto3.Session", return_value=boto3.Session())
19+
@pytest.fixture(scope="function")
20+
def mock_boto_session():
21+
"""Create a mock boto3 session for testing"""
22+
return boto3.Session(
23+
aws_access_key_id="testing",
24+
aws_secret_access_key="testing",
25+
aws_session_token="testing",
26+
region_name="us-east-1",
27+
)
28+
29+
30+
@pytest.fixture(scope="function", autouse=True)
31+
def mock_boto3_session(monkeypatch):
32+
"""Mock boto3.Session to prevent real AWS authentication"""
33+
mock_client = Mock()
34+
mock_client.head_bucket.return_value = {}
35+
36+
mock_resource = Mock()
37+
mock_resource.meta.client = mock_client
38+
mock_resource.Bucket.return_value = Mock()
39+
40+
mock_session = Mock()
41+
mock_session.resource.return_value = mock_resource
42+
43+
# Mock the boto3.Session constructor
44+
def mock_session_constructor(*args, **kwargs):
45+
return mock_session
46+
47+
monkeypatch.setattr("boto3.Session", mock_session_constructor)
48+
return mock_session
3649

3750

3851
@pytest.fixture

0 commit comments

Comments
 (0)