Skip to main content
Panther Knowledge Base

Can I use pytest or other testing frameworks to test helpers used in Panther?


Can I use pytest or other testing frameworks to test helpers used in Panther?


Yes, you can use pytest or other testing frameworks to test helpers in Panther. Since global helpers are just Python files, you can test them in your unit testing framework of choice.

For example, say this is my helper file:

    # Add your AWS account IDs/names below:
    "123456789012": "sample-account",
    "326586950245": "demo_acct"

def lookup_aws_account_name(account_id):
    """Lookup the AWS account name, return the ID if not found
        account_id (str): The AWS account ID
        str: The name of the AWS account ID
        str: The AWS account ID (unnamed account)
    return AWS_ACCOUNTS.get(account_id, f"{account_id} (unnamed account)")

Using pytest, I can write a test file like the following:

from p_dect import lookup_aws_account_name
import pytest

def test_lookup_aws_account_name():
    assert lookup_aws_account_name("326586950245") == "demo_acct"

I can then use the following command to run my test:

  • Was this article helpful?