Skip to content

Commit c3b13f6

Browse files
committed
fix(test): handle pytest collection exit code 5 as no tests found
When pytest collects no tests, it exits with code 5 which should be treated as a valid state indicating no tests rather than an error. This change properly handles this exit code in the test workflow metadata collection step, preventing false negative workflow failures. Also moved the EAGER_IMPORT environment variable definition to the job level for better organization. The fetch-depth comment was updated to reference Codecov's documentation instead of the previous unclear reasoning.
1 parent dab9a5b commit c3b13f6

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

template/.github/workflows/test.yaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,12 @@ jobs:
3939
if pytest --collect-only; then
4040
echo 'has-tests=true' >> "$GITHUB_OUTPUT"
4141
else
42-
echo 'has-tests=false' >> "$GITHUB_OUTPUT"
42+
code="$?"
43+
if (("$code" == 5)); then
44+
echo 'has-tests=false' >> "$GITHUB_OUTPUT"
45+
else
46+
exit "$code"
47+
fi
4348
fi
4449
4550
test:
@@ -50,11 +55,13 @@ jobs:
5055
- metadata
5156
if: needs.metadata.outputs.has-tests == 'true'
5257
runs-on: ubuntu-latest
58+
env:
59+
EAGER_IMPORT: true # ref: <https://github.com/scientific-python/lazy-loader?tab=readme-ov-file#early-failure>
5360
steps:
5461
- name: Checkout
5562
uses: actions/checkout@v6
5663
with:
57-
fetch-depth: 0 # I don't know why, but it is present in the official example
64+
fetch-depth: 0 # I don't know why, but it is present in Codecov's documentation
5865
- name: Setup Python
5966
uses: liblaf/actions/setup-python@v1
6067
with:

0 commit comments

Comments
 (0)