Skip to content

Commit

Permalink
Skip tests that require access to the token
Browse files Browse the repository at this point in the history
Raise an exception when the Github token is not available and use it in
order to skip tests that require access to this token.
This will allow to run a smaller set of tests from other forks and, most
importantly, won't block their merge.
  • Loading branch information
tuliom committed Feb 4, 2025
1 parent f5421dc commit c775b5c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
4 changes: 4 additions & 0 deletions snapshot_manager/snapshot_manager/github_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class Reaction(enum.StrEnum):
ROCKET = "ROCKET" # Represents the :rocket: emoji.
EYES = "EYES" # Represents the :eyes: emoji.

class MissingToken(Exception):
"""Could not retrieve a Github token."""

class GithubClient:
dirname = pathlib.Path(os.path.dirname(__file__))
Expand All @@ -52,6 +54,8 @@ def __init__(self, config: config.Config, github_token: str = None, **kwargs):
f"Reading Github token from this environment variable: {self.config.github_token_env}"
)
github_token = os.getenv(self.config.github_token_env)
if github_token is None or len(github_token) == 0:
raise MissingToken("Could not retrieve the token")
auth = github.Auth.Token(github_token)
self.github = github.Github(auth=auth)
self.gql = github_graphql.GithubGraphQL(token=github_token, raise_on_error=True)
Expand Down
16 changes: 14 additions & 2 deletions snapshot_manager/tests/github_util_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,13 @@ def test_get_todays_issue(self):
cfg = self.config
cfg.datetime = datetime.datetime(year=2024, month=2, day=27)
self.assertEqual("20240227", cfg.yyyymmdd)
gh = github_util.GithubClient(config=cfg)

try:
gh = github_util.GithubClient(config=cfg)
except MissingToken:
pytest.skip(
"Skip test because this execution doesn't have access to a Github token"
)

issue = gh.get_todays_github_issue(
strategy="big-merge", github_repo="fedora-llvm-team/llvm-snapshots"
Expand Down Expand Up @@ -104,7 +110,13 @@ def test_flip_test_label(self):
pass

def test_get_workflow(self):
gh = github_util.GithubClient(config=self.config)
try:
gh = github_util.GithubClient(config=self.config)
except MissingToken:
pytest.skip(
"Skip test because this execution doesn't have access to a Github token"
)

repo = gh.github.get_repo("fedora-llvm-team/llvm-snapshots")
workflow = repo.get_workflow("check-snapshots.yml")
self.assertIsNotNone(workflow)
Expand Down
8 changes: 7 additions & 1 deletion snapshot_manager/tests/testing_farm_util_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ def test_make_with_missing_compose(self):
cfg = self.config
cfg.datetime = datetime.datetime(year=2024, month=2, day=27)
self.assertEqual("20240227", cfg.yyyymmdd)
gh = github_util.GithubClient(config=cfg)

try:
gh = github_util.GithubClient(config=cfg)
except MissingToken:
pytest.skip(
"Skip test because this execution doesn't have access to a Github token"
)

issue = gh.get_todays_github_issue(
strategy="big-merge", github_repo="fedora-llvm-team/llvm-snapshots"
Expand Down

0 comments on commit c775b5c

Please sign in to comment.