Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
dgarros committed Sep 20, 2024
1 parent 7551e49 commit acbbfb2
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions infrahub_sdk/pytest_plugin/plugin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from pathlib import Path
from typing import Optional, Union

Expand Down Expand Up @@ -34,6 +35,7 @@ def pytest_addoption(parser: Parser) -> None:
action="store",
dest="infrahub_key",
metavar="INFRAHUB_TESTS_API_KEY",
default=os.getenv("INFRAHUB_API_TOKEN"),
help="Key to use when querying the Infrahub instance for live testing",
)
group.addoption(
Expand Down Expand Up @@ -74,12 +76,11 @@ def pytest_sessionstart(session: Session) -> None:
"default_branch": session.config.option.infrahub_branch,
}
if hasattr(session.config.option, "infrahub_key"):
client_config = {"api_token": session.config.option.infrahub_key}
client_config["api_token"] = session.config.option.infrahub_key
elif hasattr(session.config.option, "infrahub_username") and hasattr(session.config.option, "infrahub_password"):
client_config = {
"username": session.config.option.infrahub_username,
"password": session.config.option.infrahub_password,
}
client_config.pop("api_token")
client_config["username"] = session.config.option.infrahub_username
client_config["password"] = session.config.option.infrahub_password

infrahub_client = InfrahubClientSync(config=client_config)
session.infrahub_client = infrahub_client # type: ignore[attr-defined]
Expand Down

0 comments on commit acbbfb2

Please sign in to comment.