Skip to content

Commit 007105e

Browse files
committed
ci(test): improve test execution and workflow robustness
- Add GPU detection to disable parallel tests when GPU packages (jax, torch, warp) are present - Remove benchmark and test detection jobs to simplify workflows - Add --suppress-no-test-exit-code to prevent failures when no tests exist - Exclude marimo directories from ruff linting These changes ensure proper test execution for GPU-accelerated projects and prevent workflow failures when no tests are present, making the CI pipeline more robust and adaptable to different project configurations.
1 parent 1ca09a0 commit 007105e

4 files changed

Lines changed: 27 additions & 46 deletions

File tree

template/.config/copier/mise-tasks/test.sh

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,42 @@ set -o errexit
55
set -o nounset
66
set -o pipefail
77

8-
function is-true() {
9-
case "${1,,}" in
8+
function is-in-ci() {
9+
case "${CI,,}" in
1010
1 | on | true | y | yes) return 0 ;;
1111
0 | off | false | n | no | "") return 1 ;;
1212
*)
13-
echo "Invalid boolean: $1." >&2
13+
echo "Invalid boolean: $CI." >&2
1414
exit 1
1515
;;
1616
esac
1717
}
1818

19+
function needs-gpu() {
20+
for pkg in jax torch warp; do
21+
if python -c "import $pkg"; then
22+
return 0
23+
fi
24+
done
25+
return 1
26+
}
27+
1928
# ref: <https://github.com/scientific-python/lazy-loader#early-failure>
2029
export EAGER_IMPORT=1
2130

22-
if is-true "${CI-}"; then
31+
if needs-gpu; then
32+
numprocesses='0'
33+
else
34+
numprocesses='auto'
35+
fi
36+
37+
if is-in-ci; then
2338
# ref: <https://docs.codecov.com/docs/test-analytics#1-output-a-junit-xml-file-in-your-ci>
2439
pytest \
2540
--junit-xml='junit.xml' --override-ini junit_family=legacy \
2641
--cov --cov-branch \
27-
--numprocesses 'auto' \
42+
--numprocesses "$numprocesses" \
2843
"$@"
2944
else
30-
pytest --numprocesses 'auto' "$@"
45+
pytest --numprocesses "$numprocesses" "$@"
3146
fi

template/.github/workflows/bench.yaml

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,11 @@ jobs:
2323
with:
2424
cancel-others: true
2525

26-
detect:
27-
name: Detect
28-
needs:
29-
- skip-duplicate
30-
if: needs.skip-duplicate.outputs.should-skip != 'true'
31-
runs-on: ubuntu-latest
32-
outputs:
33-
bench: ${{ steps.bench.outcome == 'success' }}
34-
steps:
35-
- name: Checkout
36-
uses: actions/checkout@v5
37-
- id: bench
38-
name: Detect Benches
39-
run: |-
40-
find "benches" -name "test_*.py" -type f -print -quit |
41-
grep --quiet "benches"
42-
continue-on-error: true
43-
4426
bench:
4527
name: Bench
4628
needs:
47-
- detect
48-
if: needs.detect.outputs.bench == 'true'
29+
- skip-duplicate
30+
if: needs.skip-duplicate.outputs.should-skip != 'true'
4931
runs-on: ubuntu-latest
5032
steps:
5133
- name: Checkout

template/.github/workflows/test.yaml

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,29 +25,11 @@ jobs:
2525
with:
2626
cancel-others: true
2727

28-
detect:
29-
name: Detect
30-
needs:
31-
- skip-duplicate
32-
if: needs.skip-duplicate.outputs.should-skip != 'true'
33-
runs-on: ubuntu-latest
34-
outputs:
35-
test: ${{ steps.test.outcome == 'success' }}
36-
steps:
37-
- name: Checkout
38-
uses: actions/checkout@v5
39-
- id: test
40-
name: Detect Tests
41-
run: |-
42-
find "tests" -name "test_*.py" -type f -print -quit |
43-
grep --quiet "tests"
44-
continue-on-error: true
45-
4628
test:
4729
name: Test
4830
needs:
49-
- detect
50-
if: needs.detect.outputs.test == 'true'
31+
- skip-duplicate
32+
if: needs.skip-duplicate.outputs.should-skip != 'true'
5133
permissions:
5234
id-token: write
5335
runs-on: ubuntu-latest

template/pyproject.toml.jinja

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,12 @@ addopts = [
9494
"--showlocals",
9595
"--strict-config",
9696
"--strict-markers",
97+
"--suppress-no-test-exit-code",
9798
]
9899
testpaths = ["benches", "src", "tests"]
99100

100101
[tool.ruff]
102+
exclude = ["**/marimo/"]
101103
extend = ".config/linters/.ruff.toml"
102104

103105
# %% if package_manager == "uv":

0 commit comments

Comments
 (0)