rw_get_tests.yaml
Prepare and discover test items by scanning test directories.
Descriptionโ
This workflow runs a shell script to automatically discover all test items in your project. It's typically the first step in a testing pipeline, identifying which tests need to be executed.
Inputsโ
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
test_working_directory | string | No | ./ | The working directory for test running |
shell_path | string | No | ./scripts/ci/get-all-tests.sh | Path to the shell script that discovers test items |
shell_arg | string | Yes | - | Arguments for the shell script (typically the test directory path) |
use_customized_shell | boolean | No | false | Whether to use a custom shell script instead of the default |
Outputsโ
| Output | Description |
|---|---|
all_test_items | JSON array of all discovered test item paths |
Usage Examplesโ
Using Default Shell Script (Recommended)โ
The default shell script automatically scans the specified directory for test files:
jobs:
prepare-tests:
uses: Chisanan232/GitHub-Action_Reusable_Workflows-Python/.github/workflows/rw_get_tests.yaml@master
with:
shell_arg: test/unit_test/
Using Custom Shell Scriptโ
If you have a custom script for discovering tests:
jobs:
prepare-tests:
uses: Chisanan232/GitHub-Action_Reusable_Workflows-Python/.github/workflows/rw_get_tests.yaml@master
with:
shell_path: scripts/ci/custom-test-discovery.sh
shell_arg: unix
use_customized_shell: true
With Custom Working Directoryโ
For projects with nested structure:
jobs:
prepare-tests:
uses: Chisanan232/GitHub-Action_Reusable_Workflows-Python/.github/workflows/rw_get_tests.yaml@master
with:
test_working_directory: ./nested_project/
shell_arg: test/unit_test/
Using the Outputโ
The output can be passed to subsequent test execution workflows:
jobs:
prepare-tests:
uses: Chisanan232/GitHub-Action_Reusable_Workflows-Python/.github/workflows/rw_get_tests.yaml@master
with:
shell_arg: test/unit_test/
run-tests:
needs: prepare-tests
uses: Chisanan232/GitHub-Action_Reusable_Workflows-Python/.github/workflows/rw_run_test.yaml@master
with:
python_version: '3.11'
test_type: unit-test
all_test_items_paths: ${{ needs.prepare-tests.outputs.all_test_items }}
Default Shell Script Behaviorโ
The default shell script (get-all-tests.sh) performs the following:
- Scans the specified directory recursively
- Identifies Python test files (typically
test_*.pyor*_test.py) - Returns a JSON array of test file paths
- Handles both flat and nested test structures
Custom Shell Script Requirementsโ
If you provide a custom shell script, it must:
- Accept command-line arguments
- Output a valid JSON array of test paths
- Be executable (
chmod +x) - Return exit code 0 on success
Example custom script:
#!/bin/bash
# custom-test-discovery.sh
TEST_DIR=$1
find "$TEST_DIR" -name "test_*.py" -type f | jq -R -s -c 'split("\n")[:-1]'
Common Use Casesโ
Separate Unit and Integration Testsโ
jobs:
prepare-unit-tests:
uses: Chisanan232/GitHub-Action_Reusable_Workflows-Python/.github/workflows/rw_get_tests.yaml@master
with:
shell_arg: test/unit_test/
prepare-integration-tests:
uses: Chisanan232/GitHub-Action_Reusable_Workflows-Python/.github/workflows/rw_get_tests.yaml@master
with:
shell_arg: test/integration_test/
Multiple Test Directoriesโ
jobs:
prepare-core-tests:
uses: Chisanan232/GitHub-Action_Reusable_Workflows-Python/.github/workflows/rw_get_tests.yaml@master
with:
shell_arg: src/core/tests/
prepare-api-tests:
uses: Chisanan232/GitHub-Action_Reusable_Workflows-Python/.github/workflows/rw_get_tests.yaml@master
with:
shell_arg: src/api/tests/
Troubleshootingโ
No Tests Foundโ
If no tests are discovered:
- Verify the
shell_argpath is correct - Ensure test files follow naming conventions (
test_*.py) - Check file permissions
- Review workflow logs for error messages
Invalid JSON Outputโ
If you get JSON parsing errors:
- Verify custom shell script outputs valid JSON
- Check for trailing newlines or extra characters
- Test the shell script locally before using in workflow
Related Workflowsโ
- rw_run_test - Execute discovered tests
- rw_poetry_run_test - Execute tests with Poetry
- rw_run_test_with_multi_py_versions - Multi-version testing