Skip to content

Commit

Permalink
compatible(pytest_plugins/github_secrets): Skip tests when secrets un…
Browse files Browse the repository at this point in the history
…available (#91)

By default, PRs from forks do not have access to GitHub secrets on the
base repository.

Skip tests that require GitHub secrets when running on a PR from a fork
  • Loading branch information
carlcsaposs-canonical authored Nov 14, 2023
1 parent 7b15b32 commit 317190b
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions python/pytest_plugins/github_secrets/github_secrets/plugin.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import ast
import logging
import os

import pytest

logger = logging.getLogger(__name__)


@pytest.fixture(scope="session")
def github_secrets() -> dict[str, str]:
Expand All @@ -25,4 +28,9 @@ def github_secrets() -> dict[str, str]:
raise Exception(
"Invalid format for `SECRETS_FROM_GITHUB`—must be a Python dict[str, str]"
)
if set(secrets.values()) == {""}:
logger.warning(
"No GitHub secrets available: skipping tests that require GitHub secrets"
)
pytest.skip("Running on fork: no access to GitHub secrets")
return secrets

0 comments on commit 317190b

Please sign in to comment.