Skip to content

Commit

Permalink
Tests: Unlock running the test suite without OPS credentials
Browse files Browse the repository at this point in the history
While it will only cover parts of the test suite, which is unfortunate,
at least it will not break. This is relevant for CI/GHA, because pull
requests submitted by external contributors do not have access to the
OPS credentials per GitHub Actions Secrets. C'est la vie.
  • Loading branch information
amotl committed Jan 28, 2024
1 parent a024610 commit 542f3d1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
12 changes: 7 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest

from .helpers import mkcache, mksqlite, mkthrottler
from .secrets import OPS_KEY, OPS_SECRET
from .secrets import get_secrets_or_skip_tests


@pytest.fixture
Expand All @@ -12,9 +12,9 @@ def storage(request):
@pytest.fixture
def reset_cached_client(request):
from epo_ops import Client

ops_key, ops_secret = get_secrets_or_skip_tests()
return Client(
OPS_KEY, OPS_SECRET, middlewares=[mkcache(request), mkthrottler(request)]
ops_key, ops_secret, middlewares=[mkcache(request), mkthrottler(request)]
)


Expand All @@ -31,15 +31,17 @@ def module_cache(request):
@pytest.fixture(scope="module")
def default_client(request):
from epo_ops import Client
ops_key, ops_secret = get_secrets_or_skip_tests()

return Client(OPS_KEY, OPS_SECRET, middlewares=[mkthrottler(request)])
return Client(ops_key, ops_secret, middlewares=[mkthrottler(request)])


@pytest.fixture(scope="module")
def cached_client(request, module_cache):
from epo_ops import Client
ops_key, ops_secret = get_secrets_or_skip_tests()

return Client(OPS_KEY, OPS_SECRET, middlewares=[module_cache, mkthrottler(request)])
return Client(ops_key, ops_secret, middlewares=[module_cache, mkthrottler(request)])


@pytest.fixture(scope="module", params=["cached_client", "default_client"])
Expand Down
12 changes: 10 additions & 2 deletions tests/secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import os
from os.path import abspath, dirname, join

import pytest
from dotenv import load_dotenv

# Prune environment variables.
Expand All @@ -20,6 +21,13 @@
dotenv_path = abspath(join(dirname(__file__), "../.env"))
load_dotenv(dotenv_path)


# Set environment variables as constants.
OPS_KEY = os.environ["OPS_KEY"]
OPS_SECRET = os.environ["OPS_SECRET"]
def get_secrets_or_skip_tests():
try:
ops_key = os.environ["OPS_KEY"]
ops_secret = os.environ["OPS_SECRET"]
except KeyError as ex:
raise pytest.skip("No OPS credentials configured") from ex

return ops_key, ops_secret

0 comments on commit 542f3d1

Please sign in to comment.