Skip to content

Commit

Permalink
fine tune test skipping (opengisch#295)
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids authored and nirvn committed Aug 1, 2024
1 parent 7e9b288 commit 138924d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
6 changes: 3 additions & 3 deletions test/test_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from qgispluginci.utils import replace_in_file

# Tests
from .utils import can_skip_test
from .utils import can_skip_test_github

# If changed, also update CHANGELOG.md
RELEASE_VERSION_TEST = "0.1.2"
Expand Down Expand Up @@ -89,7 +89,7 @@ def test_release_with_empty_tx_token(self):
tx_api_token="",
)

@unittest.skipIf(can_skip_test(), "Missing tx_api_token")
@unittest.skipIf(can_skip_test_github(), "Missing tx_api_token")
def test_release_with_transifex(self):
Translation(self.qgis_plugin_config_params, tx_api_token=self.tx_api_token)
release(
Expand Down Expand Up @@ -118,7 +118,7 @@ def test_zipname(self):
) # check that there is only one log message
self.assertEqual(captured.records[0].getMessage(), DASH_WARNING)

@unittest.skipIf(can_skip_test(), "Missing github_token")
@unittest.skipIf(can_skip_test_github(), "Missing github_token")
def test_release_upload_github(self):
release(
self.qgis_plugin_config_params,
Expand Down
4 changes: 2 additions & 2 deletions test/test_translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from qgispluginci.translation import Translation

# Tests
from .utils import can_skip_test
from .utils import can_skip_test_transifex

# Logging
logger = logging.getLogger(__name__)
Expand All @@ -22,7 +22,7 @@
unittest.TestLoader.sortTestMethodsUsing = None


@unittest.skipIf(can_skip_test(), "Missing tx_api_token")
@unittest.skipIf(can_skip_test_transifex(), "Missing tx_api_token")
class TestTranslation(unittest.TestCase):
@classmethod
def setUpClass(cls):
Expand Down
23 changes: 19 additions & 4 deletions test/utils.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
import os


def can_skip_test():
"""Check when a test can run."""
def can_skip_test_github():
"""Check when the Transifex test can run."""
is_ci = os.getenv("CI") == "true"
is_main_repo = os.getenv("GITHUB_REPOSITORY") == "opengisch/qgis-plugin-ci"

if is_ci and is_main_repo:
return False

if not os.getenv("github_token"):
return True

return False


def can_skip_test_transifex():
"""Check when the Transifex test can run."""
is_ci = os.getenv("CI") == "true"
is_main_repo = os.getenv("GITHUB_REPOSITORY") == "opengisch/qgis-plugin-ci"
is_dependabot = os.getenv("GITHUB_ACTOR") == "dependabot[bot]"

if is_ci and is_main_repo and not is_dependabot:
# Always run the test on CI
return False

if not os.getenv("tx_api_token") or not os.getenv("github_token"):
# On local, the token must be set
if not os.getenv("tx_api_token"):
return True

return False

0 comments on commit 138924d

Please sign in to comment.