From 22508cf16695621183c0a5f5fe76d14ffaf48bae Mon Sep 17 00:00:00 2001 From: Kevin Barnard Date: Tue, 16 Jul 2024 11:44:54 -0700 Subject: [PATCH] fix: make TEST_X_API_KEY use an environment variable of the same name --- test/__init__.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/test/__init__.py b/test/__init__.py index 5211b97..4b49c9c 100644 --- a/test/__init__.py +++ b/test/__init__.py @@ -1,18 +1,27 @@ +from os import getenv from unittest import skipIf from fathomnet.api import xapikey -# Set this to an API key in order to perform authentication and enable test cases decorated by @skipIfNoAuth -TEST_X_API_KEY = None +# Set the TEST_X_API_KEY environment variable an API key in order to perform authentication and enable test cases decorated by @skipIfNoAuth +TEST_X_API_KEY = getenv("TEST_X_API_KEY") - -if ( - TEST_X_API_KEY is not None -): # If test X-API-Key is provided, authenticate session to enable cases +# If test X-API-Key is provided, authenticate session to enable cases +if TEST_X_API_KEY is not None: xapikey.auth(TEST_X_API_KEY) -def skipIfNoAuth(f): # Decorator to skip test case if it needs auth +def skipIfNoAuth(f: callable) -> callable: + """ + Decorator to skip test case if it needs auth. + + Args: + f (callable): Test case function. + + Returns: + callable: Test case function + """ return skipIf( - TEST_X_API_KEY is None, "Test X-API-Key not specified. (see test/__init__.py)" + TEST_X_API_KEY is None, + "TEST_X_API_KEY environment variable not specified", )(f)