Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fine tune test skipping #295

Merged
merged 1 commit into from
Apr 3, 2024
Merged
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
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