Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions test/framework/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,26 @@ def requires_github_access():

Useful when the test uses e.g. `git` commands to download from Github and would run into rate limits
"""
if 'FORCE_EB_GITHUB_TESTS' in os.environ or os.getenv('GITHUB_EVENT_NAME') != 'pull_request':
return unittest.skipIf(False, None)
else:
# For pull requests silently skip to avoid rate limits
def decorator(test_item):
@functools.wraps(test_item)
def skip_wrapper(*args, **kwargs):
return
return skip_wrapper
return decorator
return unittest.skipUnless(
os.environ.get('FORCE_EB_GITHUB_TESTS', '0') != '0' or os.getenv('GITHUB_EVENT_NAME') != 'pull_request',
"Skipping test requiring GitHub access"
)


def ignore_rate_limit_in_pr(test_item):
"""Decorator: If tests are run in a pull request and fail with a rate limit error, ignore that"""
if os.environ.get('FORCE_EB_GITHUB_TESTS', '0') != '0' or os.getenv('GITHUB_EVENT_NAME') != 'pull_request':
return test_item

@functools.wraps(test_item)
def skip_wrapper(self, *args, **kwargs):
try:
test_item(self, *args, **kwargs)
except EasyBuildError as e:
if 'HTTP Error 403' in e.msg:
self.skipTest('Ignoring rate limit error')
raise
return skip_wrapper


class GithubTest(EnhancedTestCase):
Expand Down Expand Up @@ -518,6 +528,7 @@ def test_github_fetch_files_from_pr_cache(self):
res = gh.fetch_easyblocks_from_pr(12345, tmpdir)
self.assertEqual(sorted(pr12345_files), sorted(res))

@ignore_rate_limit_in_pr
def test_fetch_files_from_commit(self):
"""Test fetch_files_from_commit function."""

Expand Down Expand Up @@ -551,6 +562,7 @@ def test_fetch_files_from_commit(self):
error_pattern = r"Failed to download diff for easybuilders/easybuild-easyconfigs commit c0ff33c0ff33"
self.assertErrorRegex(EasyBuildError, error_pattern, fetch_files_from_commit, 'c0ff33c0ff33')

@ignore_rate_limit_in_pr
def test_fetch_easyconfigs_from_commit(self):
"""Test fetch_easyconfigs_from_commit function."""

Expand Down
2 changes: 2 additions & 0 deletions test/framework/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
from easybuild.tools.systemtools import DARWIN, HAVE_ARCHSPEC, get_os_type
from easybuild.tools.version import VERSION
from test.framework.utilities import EnhancedTestCase, TestLoaderFiltered, cleanup, init_config
from test.framework.github import ignore_rate_limit_in_pr

try:
import pycodestyle # noqa
Expand Down Expand Up @@ -1521,6 +1522,7 @@ def test_github_copy_ec_from_pr(self):
self.assertIn("name = 'EasyBuild'", read_file(test_ec))
remove_file(test_ec)

@ignore_rate_limit_in_pr
def test_copy_ec_from_commit(self):
"""Test combination of --copy-ec with --from-commit."""
# note: --from-commit does not involve using GitHub API, so no GitHub token required
Expand Down