My tests currently run as part of Checks on every Commit, but they take a while to run. Is there a way I can only run the tests on certain branches (e.g., a staging branch)?
My tests currently run as part of Checks on every Commit, but they take a while to run. Is there a way I can only run the tests on certain branches (e.g., a staging branch)?
PySpark tests in Foundry run using PyTest. As a result, you can use PyTest's built-in functionality to control whether a test should run or be skipped.
In Foundry, you can see which branch your code is running on in Checks using the JEMMA_BRANCH environment variable (n.b.: this variable won't be set during a Build, only in checks).
Combining this with PyTest's skipif mark, you can configure your tests to only run on particular branches as follows:
import os
import pytest
def only_run_on_branches(run_branches):
current_branch = os.environ.get('JEMMA_BRANCH')
return pytest.mark.skipif(
current_branch not in run_branches and current_branch is not None,
reason=f"Not running test on current branch ('{current_branch}')"
)
@only_run_on_branches(["master"])
def test_increment():
assert "testing" == "hard"
You can find more documentation on testing PySpark in Foundry here, and on skipping tests in PyTest here. That page also shows you how you can skip entire files or directories based on arbitrary logic, too.