Datarax Testing Guide
September 16, 2026 ยท View on GitHub
This guide explains how to run tests in the Datarax codebase, with special attention to CPU and GPU testing configurations.
Test Setup Overview
Datarax has a flexible testing setup that:
- Runs all tests on CPU by default (both locally and in CI)
- Automatically runs tests on GPU as well if a GPU is available locally
- Never attempts GPU tests in GitHub workflows
Running Tests
Quick Start
The simplest way to run tests is with the run_tests.sh script:
# Run core tests (tests/ only)
uv run pytest
# Run ALL test suites (tests/ + benchmarks/tests/)
uv run pytest --all-suites
# Run all tests, automatically using both CPU and GPU if available
./run_tests.sh
# Run only CPU tests regardless of GPU availability
./run_tests.sh --device=cpu
# Run only GPU tests (will fail if no GPU is available)
./run_tests.sh --device=gpu
# Run specific test categories
./run_tests.sh --integration # Run integration tests
./run_tests.sh --end-to-end # Run end-to-end tests
./run_tests.sh --benchmark # Run benchmark tests
./run_tests.sh --all # Run all test categories
Unified GPU/CPU Test Runner
The main test runner at scripts/run_tests.sh (also available via ./run_tests.sh at the root) handles everything:
./run_tests.sh # Auto-detect GPU, run on CPU (and GPU if available)
./run_tests.sh --device=cpu # Force CPU only
./run_tests.sh --device=gpu # Force GPU only
This script:
- Checks if
uvis installed - Safely detects GPU availability
- Runs all tests on CPU first
- If a GPU is available, also runs on GPU
- Tracks exit codes properly across both runs
GPU-Specific Testing
To run only GPU-specific tests with CUDA configuration:
./scripts/run_gpu_tests.sh
This script:
- Checks if a GPU is available
- Sets up the proper environment variables for GPU testing
- Runs the GPU test suite via pytest
Test Configuration
Tests are configured with several pytest markers and command-line options:
Test Suite Selection
--all-suites: Collect all test suites (tests/,benchmarks/tests/). Without this flag, onlytests/is collected (configured inpyproject.tomlviatestpaths).
Test Backend
- Tests run on eight emulated CPU devices by default
DATARAX_TEST_JAX_PLATFORMS=cuda: run the tests on the GPUDATARAX_TEST_DEVICE_COUNT=N: emulateNCPU devices
Test Categories
--integration: Run integration tests--end-to-end: Run end-to-end tests--benchmark: Run benchmark tests--no-integration: Skip integration tests--no-end-to-end: Skip end-to-end tests
Test Markers
@pytest.mark.accelerator(kind="gpu"): Test needs a GPU backend (substrax plugin)@pytest.mark.devices(count): Test needs at leastcountdevices (substrax plugin)@pytest.mark.integration: Integration test@pytest.mark.end_to_end: End-to-end test@pytest.mark.benchmark: Performance benchmark test@pytest.mark.tfds: Test requires TensorFlow Datasets@pytest.mark.hf: Test requires HuggingFace Datasets
CI/GitHub Workflow Testing
All GitHub workflow tests run exclusively on CPU regardless of the availability of GPU instances. This ensures consistent test results and avoids issues with GPU availability in CI environments.
The following workflows are configured to run tests on CPU:
ci.yml: Main CI workflow, including unit, integration, end-to-end, performance, and combined coverage jobs
Writing Device-Specific Tests
Declare what a test needs, and the substrax pytest plugin skips it when the run cannot provide it:
import pytest
# Runs on whatever backend the run selected
def test_basic_functionality():
...
# Runs only when the run selected a GPU backend
@pytest.mark.accelerator(kind="gpu")
def test_gpu_specific_functionality():
...
# Runs only with at least two visible devices
@pytest.mark.devices(2)
def test_multi_device_sharding():
...
Troubleshooting
GPU Tests Failing
If GPU tests are failing but CPU tests pass:
- Check if your GPU is properly detected:
uv run python scripts/check_gpu.py - Ensure you have the correct JAX CUDA version installed
- Try setting
XLA_CLIENT_MEM_FRACTION=0.5to limit memory usage - Check for CUDA version mismatches between JAX and your system
- Regenerate the backend configuration in
.datarax.env(run./setup.sh --backend cuda12to configure the CUDA 12 backend)
Test Selection Issues
If tests aren't being selected correctly:
- Check that you're using the correct markers
- Ensure pytest is correctly interpreting command-line arguments
- Try running with
-vfor verbose output to see which tests are selected