PR

prowler-test-sdk

Provides Prowler-specific testing patterns and mocking standards for Python SDK development.

Install

mkdir -p .claude/skills/prowler-test-sdk && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/7065" && unzip -o skill.zip -d .claude/skills/prowler-test-sdk && rm skill.zip

Installs to .claude/skills/prowler-test-sdk

Activation

This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.

Testing patterns for Prowler SDK (Python). Trigger: When writing tests for the Prowler SDK (checks/services/providers), including provider-specific mocking rules (moto for AWS only).
182 chars · catalog description✓ has a “when” trigger
Intermediate

Key capabilities

  • →Mock AWS services with moto
  • →Mock non-AWS providers with MagicMock
  • →Configure Prowler global provider fixtures
  • →Verify check execution output

How it works

It selects the mocking library based on the target provider, ensuring AWS tests use the moto decorator while others use MagicMock.

Inputs & outputs

You give it
Prowler check implementation code
You get back
Pytest test file with appropriate mocking

When to use prowler-test-sdk

  • →Writing unit tests for AWS checks
  • →Configuring moto mocks for cloud services
  • →Standardizing provider-specific test logic

About this skill

Generic Patterns: For base pytest patterns (fixtures, mocking, parametrize), see the pytest skill. This skill covers Prowler-specific conventions only. Full guide: docs/developer-guide/unit-testing.mdx.

Mocking Approach by Provider

ProviderApproach
AWS, API covered by moto@mock_aws, create real resources with boto3.client(...), instantiate the real service class
AWS, API not or partially covered by motoPatch botocore.client.BaseClient._make_api_call (wrap responses with mocked_api_response), or inject a MagicMock service client in check tests
Every other providerMagicMock() service client with Pydantic models from {service}_service.py

Never use moto for non-AWS providers. For AWS, prefer moto and fall back to botocore/MagicMock only when moto lacks the API (check moto's IMPLEMENTATION_COVERAGE.md).

Critical Rules

  • Import the check inside the mock.patch context, otherwise the real {service}_client singleton is built at import time.
  • Patch prowler.providers.common.provider.Provider.get_global_provider and the client where the check imports it: prowler.providers.{provider}.services.{service}.{check_name}.{check_name}.{service}_client.
  • Prefer mock.MagicMock() (an instance). Older tests assign attributes on the class (client = mock.MagicMock); tests/conftest.py resets those after every test, but new tests should use instances.
  • Tests run in random order (pytest-randomly) and in parallel (-n auto): no shared state between tests.
  • Test file basenames must be unique across tests/ (no __init__.py; the SDK: Check Duplicate Test Names workflow fails on duplicates). Prefix with the provider if needed: stackit_objectstorage_service_test.py.
  • Do not create __init__.py files in test folders.

AWS Check Test (moto)

from unittest import mock

from boto3 import client
from moto import mock_aws

from tests.providers.aws.utils import AWS_REGION_US_EAST_1, set_mocked_aws_provider


class Test_s3_bucket_object_versioning:
    @mock_aws
    def test_bucket_no_versioning(self):
        s3 = client("s3", region_name=AWS_REGION_US_EAST_1)
        s3.create_bucket(Bucket="bucket-test")

        from prowler.providers.aws.services.s3.s3_service import S3

        aws_provider = set_mocked_aws_provider([AWS_REGION_US_EAST_1])

        with (
            mock.patch(
                "prowler.providers.common.provider.Provider.get_global_provider",
                return_value=aws_provider,
            ),
            mock.patch(
                "prowler.providers.aws.services.s3.s3_bucket_object_versioning.s3_bucket_object_versioning.s3_client",
                new=S3(aws_provider),
            ),
        ):
            from prowler.providers.aws.services.s3.s3_bucket_object_versioning.s3_bucket_object_versioning import (
                s3_bucket_object_versioning,
            )

            result = s3_bucket_object_versioning().execute()

            assert len(result) == 1
            assert result[0].status == "FAIL"
            assert result[0].status_extended == "S3 Bucket bucket-test has versioning disabled."
            assert result[0].resource_id == "bucket-test"
            assert result[0].region == AWS_REGION_US_EAST_1

set_mocked_aws_provider() (tests/providers/aws/utils.py) takes audited_regions (a list, never None), audit_config={...} for configurable checks, fixer_config, scan_unused_services, expected_checks, and more; read its signature.

AWS: API Not Covered by moto

import botocore
from unittest.mock import patch

from tests.providers.aws.utils import mocked_api_response

orig = botocore.client.BaseClient._make_api_call


def mock_make_api_call(self, operation_name, api_params):
    if operation_name == "DescribeOrganizationConfiguration":
        # mocked_api_response fails the test if the dict does not match the real API output shape
        return mocked_api_response(
            "guardduty", operation_name, {"AutoEnableOrganizationMembers": "ALL", "MemberAccountLimitReached": False}
        )
    return orig(self, operation_name, api_params)


@patch("botocore.client.BaseClient._make_api_call", new=mock_make_api_call)
@mock_aws
def test_...(self): ...

Other Providers (MagicMock)

from unittest import mock

from prowler.providers.azure.services.storage.storage_service import Account
from tests.providers.azure.azure_fixtures import (
    AZURE_SUBSCRIPTION_ID,
    AZURE_SUBSCRIPTION_NAME,
    set_mocked_azure_provider,
)


def test_no_storage_accounts():
    storage_client = mock.MagicMock()
    storage_client.storage_accounts = {}
    storage_client.subscriptions = {AZURE_SUBSCRIPTION_ID: AZURE_SUBSCRIPTION_NAME}

    with (
        mock.patch(
            "prowler.providers.common.provider.Provider.get_global_provider",
            return_value=set_mocked_azure_provider(),
        ),
        mock.patch(
            "prowler.providers.azure.services.storage.{check_name}.{check_name}.storage_client",
            new=storage_client,
        ),
    ):
        from prowler.providers.azure.services.storage.{check_name}.{check_name} import {check_name}

        assert len({check_name}().execute()) == 0

Set every attribute the check reads on the mock (e.g. Azure checks read storage_client.subscriptions); a missing one silently returns a MagicMock, or raises AttributeError on a bare-class mock.

Provider Fixtures

ProviderFileFunctionKey constants
AWStests/providers/aws/utils.pyset_mocked_aws_providerAWS_REGION_US_EAST_1, AWS_ACCOUNT_NUMBER, AWS_COMMERCIAL_PARTITION
Azuretests/providers/azure/azure_fixtures.pyset_mocked_azure_providerAZURE_SUBSCRIPTION_ID, AZURE_SUBSCRIPTION_NAME, AZURE_SUBSCRIPTION_DISPLAY
GCPtests/providers/gcp/gcp_fixtures.pyset_mocked_gcp_providerGCP_PROJECT_ID, GCP_EU1_LOCATION
Kubernetestests/providers/kubernetes/kubernetes_fixtures.pyset_mocked_kubernetes_providerKUBERNETES_CLUSTER_NAME, KUBERNETES_NAMESPACE
M365tests/providers/m365/m365_fixtures.pyset_mocked_m365_providerTENANT_ID, DOMAIN
GitHubtests/providers/github/github_fixtures.pyset_mocked_github_providerACCOUNT_NAME, ACCOUNT_ID
Oracle Cloudtests/providers/oraclecloud/oci_fixtures.pyset_mocked_oraclecloud_providerOCI_TENANCY_ID, OCI_COMPARTMENT_ID
Otherstests/providers/{provider}/{provider}_fixtures.pyset_mocked_{provider}_providerread the file

iac and image fixtures expose sample tool outputs instead of a mocked provider.

Test Layout

tests/providers/{provider}/
├── {provider}_fixtures.py
├── {provider}_provider_test.py
└── services/{service}/
    ├── {service}_service_test.py          # service fetch logic
    └── {check_name}/
        ├── {check_name}_test.py           # check logic
        └── {check_name}_fixer_test.py     # if the check has a fixer

Required Scenarios per Check

ScenarioExpected
No resourceslen(result) == 0
Compliant resourcestatus == "PASS"
Non-compliant resourcestatus == "FAIL"
Data could not be retrievedlen(result) == 0 (never MANUAL)
Multiple resourcescorrect count, one finding per resource

Assert status_extended (exact string), resource_id, resource_name/resource_arn, and the location field (region, subscription/location, project_id/location, namespace).

CI Notes

  • .github/workflows/sdk-tests.yml runs each provider's tests only when its files change. For AWS, a service's tests also run when a service it depends on changes: update the dependents table there (and in unit-testing.mdx) when a check imports another service's client.
  • tests/lib/check/check_test.py validates all metadata files per provider (test_{provider}_checks_metadata_is_valid).

Commands

uv run pytest -n auto tests/providers/{provider}/services/{service}/{check_name}/   # one check
uv run pytest -n auto tests/providers/{provider}/                                  # one provider
uv run pytest tests/path/file_test.py -k "test_name" -vv                           # one test
uv run pytest -p no:randomly tests/path/                                           # reproduce order-dependent failures
uv run pytest -n auto tests/                                                       # full SDK suite (slow)

Resources

When not to use it

  • →Testing logic unrelated to Prowler providers
  • →Writing E2E tests for the UI

Prerequisites

motopytest

Limitations

  • →Requires explicit test class structure
  • →Strict separation between AWS and non-AWS mocking

How it compares

It enforces provider-specific isolation testing boundaries that avoid invalid mocking strategies.

Compared to similar skills

prowler-test-sdk side by side with the closest alternatives in the catalog.

SkillInstallsUpdatedSafetyDifficulty
prowler-test-sdk (this skill)15moReviewIntermediate
python-testing-patterns776moReviewIntermediate
backtesting-frameworks176moNo flagsAdvanced
temporal-python-testing87moNo flagsAdvanced

Try saying

Example prompts that trigger this skill in your AI assistant.

You might also like

Search skills

Search the agent skills registry