Skip to content

Commit

Permalink
fix: make TEST_X_API_KEY use an environment variable of the same name
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinsbarnard committed Jul 16, 2024
1 parent 0190345 commit 22508cf
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions test/__init__.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 22508cf

Please sign in to comment.