Skip to content

Commit

Permalink
🧪 testing env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
juftin committed Dec 17, 2023
1 parent e90de97 commit f9d41e0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
8 changes: 0 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,6 @@ dependencies = [
"vcrpy~=5.1.0"
]

[tool.hatch.envs.test.env-vars]
LUNCHMONEY_ACCESS_TOKEN = "{env:LUNCHMONEY_ACCESS_TOKEN:LUNCHMONEY_ACCESS_TOKEN_PLACEHOLDER}"
PUSHOVER_USER_KEY = "{env:PUSHOVER_USER_KEY:PUSHOVER_USER_KEY_PLACEHOLDER}"
SENSITIVE_REQUEST_STRINGS = "{env:SENSITIVE_REQUEST_STRINGS:SENSITIVE_REQUEST_STRINGS_PLACEHOLDER}"
SPLITWISE_API_KEY = "{env:SPLITWISE_API_KEY:SPLITWISE_API_KEY_PLACEHOLDER}"
SPLITWISE_CONSUMER_KEY = "{env:SPLITWISE_CONSUMER_KEY:SPLITWISE_CONSUMER_KEY_PLACEHOLDER}"
SPLITWISE_CONSUMER_SECRET = "{env:SPLITWISE_CONSUMER_SECRET:SPLITWISE_CONSUMER_SECRET_PLACEHOLDER}"

[tool.hatch.envs.test.scripts]
cov = [
"test-cov",
Expand Down
18 changes: 17 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,23 @@
module_scope = pytest.fixture(scope="module")


@pytest.fixture(autouse=True)
def set_test_env_vars(monkeypatch: pytest.MonkeyPatch) -> None:
"""
Set Environment Variables for Testing if they are not already set
"""
testing_env_vars = [
"LUNCHMONEY_ACCESS_TOKEN",
"PUSHOVER_USER_KEY",
"SPLITWISE_API_KEY",
"SPLITWISE_CONSUMER_KEY",
"SPLITWISE_CONSUMER_SECRET",
]
for env_var in testing_env_vars:
if not os.getenv(env_var):
monkeypatch.setenv(env_var, f"{env_var}_PLACEHOLDER")


@pytest.fixture
def obscure_start_date() -> datetime.datetime:
"""
Expand Down Expand Up @@ -148,7 +165,6 @@ def path_transformer(path: str) -> str:
record_mode=os.getenv("VCR_RECORD_MODE", "once"),
)


# Decorator Object to Use pyvcr Cassettes on Unit Tests
# pass `--vcr-record=none` to pytest CI runs to ensure new cassettes are generated
lunchable_cassette = vcr.use_cassette

0 comments on commit f9d41e0

Please sign in to comment.