diff --git a/pyproject.toml b/pyproject.toml index 00d970f4..f19d2f1b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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", diff --git a/tests/conftest.py b/tests/conftest.py index c665bf77..edb0b02c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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: """ @@ -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