Skip to main content
Version: Next

rw_get_tests.yaml

Prepare and discover test items by scanning test directories.

View Source

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โ€‹

ParameterTypeRequiredDefaultDescription
test_working_directorystringNo./The working directory for test running
shell_pathstringNo./scripts/ci/get-all-tests.shPath to the shell script that discovers test items
shell_argstringYes-Arguments for the shell script (typically the test directory path)
use_customized_shellbooleanNofalseWhether to use a custom shell script instead of the default

Outputsโ€‹

OutputDescription
all_test_itemsJSON array of all discovered test item paths

Usage Examplesโ€‹

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:

  1. Scans the specified directory recursively
  2. Identifies Python test files (typically test_*.py or *_test.py)
  3. Returns a JSON array of test file paths
  4. Handles both flat and nested test structures

Custom Shell Script Requirementsโ€‹

If you provide a custom shell script, it must:

  1. Accept command-line arguments
  2. Output a valid JSON array of test paths
  3. Be executable (chmod +x)
  4. 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:

  1. Verify the shell_arg path is correct
  2. Ensure test files follow naming conventions (test_*.py)
  3. Check file permissions
  4. Review workflow logs for error messages

Invalid JSON Outputโ€‹

If you get JSON parsing errors:

  1. Verify custom shell script outputs valid JSON
  2. Check for trailing newlines or extra characters
  3. Test the shell script locally before using in workflow