Can I use pytest or other testing frameworks to test helpers used in Panther?
ANSWER
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:
#p_dect.py AWS_ACCOUNTS = { # 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 Args: account_id (str): The AWS account ID Returns: str: The name of the AWS account ID or 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:
#p_dect_test.py 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:
pytest p_dect_test.py