Skip to content

Commit 96458da

Browse files
Test work flow build failed
1 parent 17519ed commit 96458da

6 files changed

Lines changed: 89 additions & 14 deletions

File tree

src/ContentProcessor/pytest.ini

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[tool:pytest]
2+
addopts = -v --strict-markers --disable-warnings
3+
python_files = tests.py test_*.py *_tests.py
4+
testpaths = tests
5+
markers =
6+
asyncio: marks tests as async

src/ContentProcessor/src/tests/azure_helper/test_storage_blob.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
1+
pytest_plugins = ["pytest_mock"]
2+
13
import pytest
24
from io import BytesIO
3-
from unittest.mock import patch
5+
from unittest.mock import MagicMock
46
from libs.azure_helper.storage_blob import StorageBlobHelper
57

68

7-
@pytest.fixture(autouse=True)
8-
def mock_azure_credentials(mocker):
9-
"""Mock Azure credentials to prevent real authentication attempts during tests."""
10-
mocker.patch("azure.identity.DefaultAzureCredential")
11-
mocker.patch("azure.identity.ManagedIdentityCredential")
12-
mocker.patch("helpers.azure_credential_utils.get_azure_credential", return_value="mock_credential")
13-
14-
159
@pytest.fixture
1610
def mock_blob_service_client(mocker):
11+
"""Mock BlobServiceClient to prevent any network calls."""
1712
return mocker.patch("azure.storage.blob.BlobServiceClient")
1813

1914

2015
@pytest.fixture
21-
def storage_blob_helper(mock_blob_service_client, mock_azure_credentials):
16+
def storage_blob_helper(mock_blob_service_client):
17+
"""Create StorageBlobHelper with all Azure services mocked via conftest.py."""
2218
return StorageBlobHelper(
2319
account_url="https://testaccount.blob.core.windows.net",
2420
container_name="testcontainer",
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""
2+
Global test configuration and fixtures for ContentProcessor tests.
3+
"""
4+
import pytest
5+
from unittest.mock import patch, MagicMock
6+
7+
pytest_plugins = ["pytest_mock"]
8+
9+
10+
@pytest.fixture(autouse=True, scope="session")
11+
def mock_azure_services():
12+
"""
13+
Mock all Azure services and credentials to prevent real authentication
14+
and network calls during testing.
15+
"""
16+
with patch("azure.identity.DefaultAzureCredential") as mock_default, \
17+
patch("azure.identity.ManagedIdentityCredential") as mock_managed, \
18+
patch("helpers.azure_credential_utils.get_azure_credential") as mock_get_cred, \
19+
patch("helpers.azure_credential_utils.get_azure_credential_async") as mock_get_cred_async:
20+
21+
# Create mock credential objects
22+
mock_credential = MagicMock()
23+
mock_default.return_value = mock_credential
24+
mock_managed.return_value = mock_credential
25+
mock_get_cred.return_value = mock_credential
26+
mock_get_cred_async.return_value = mock_credential
27+
28+
yield {
29+
"credential": mock_credential,
30+
"default": mock_default,
31+
"managed": mock_managed,
32+
"get_credential": mock_get_cred,
33+
"get_credential_async": mock_get_cred_async
34+
}

src/ContentProcessor/src/tests/test_main.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
pytest_plugins = ["pytest_mock"]
2+
13
import pytest
24
from main import Application
35

@@ -36,10 +38,7 @@ async def test_application_run(mocker):
3638
"libs.process_host.handler_process_host.HandlerHostManager"
3739
).return_value
3840

39-
# Mock Azure credentials to prevent real authentication attempts
40-
mocker.patch("azure.identity.DefaultAzureCredential")
41-
mocker.patch("azure.identity.ManagedIdentityCredential")
42-
mocker.patch("helpers.azure_credential_utils.get_azure_credential", return_value="mock_credential")
41+
# Note: Azure credentials are mocked globally via conftest.py
4342

4443
# Mock the read_configuration method to return a complete configuration
4544
mocker.patch(

src/ContentProcessorAPI/pytest.ini

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[tool:pytest]
2+
addopts = -v --strict-markers --disable-warnings
3+
python_files = tests.py test_*.py *_tests.py
4+
testpaths = tests
5+
markers =
6+
asyncio: marks tests as async
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""
2+
Global test configuration and fixtures for ContentProcessorAPI tests.
3+
"""
4+
import pytest
5+
from unittest.mock import patch, MagicMock
6+
7+
pytest_plugins = ["pytest_mock"]
8+
9+
10+
@pytest.fixture(autouse=True, scope="session")
11+
def mock_azure_services():
12+
"""
13+
Mock all Azure services and credentials to prevent real authentication
14+
and network calls during testing.
15+
"""
16+
with patch("azure.identity.DefaultAzureCredential") as mock_default, \
17+
patch("azure.identity.ManagedIdentityCredential") as mock_managed, \
18+
patch("helpers.azure_credential_utils.get_azure_credential") as mock_get_cred, \
19+
patch("helpers.azure_credential_utils.get_azure_credential_async") as mock_get_cred_async:
20+
21+
# Create mock credential objects
22+
mock_credential = MagicMock()
23+
mock_default.return_value = mock_credential
24+
mock_managed.return_value = mock_credential
25+
mock_get_cred.return_value = mock_credential
26+
mock_get_cred_async.return_value = mock_credential
27+
28+
yield {
29+
"credential": mock_credential,
30+
"default": mock_default,
31+
"managed": mock_managed,
32+
"get_credential": mock_get_cred,
33+
"get_credential_async": mock_get_cred_async
34+
}

0 commit comments

Comments
 (0)