Configure parallel tests with Pytest - AWS CodeBuild
Services or capabilities described in AWS documentation might vary by Region. To see the differences applicable to the AWS European Sovereign Cloud Region, see the AWS European Sovereign Cloud User Guide.

Configure parallel tests with Pytest

The following is sample of a buildspec.yml that shows parallel test execution with Pytest on an Ubuntu platform:

version: 0.2 batch: fast-fail: false build-fanout: parallelism: 5 ignore-failure: false phases: install: commands: - echo 'Installing Python dependencies' - apt-get update - apt-get install -y python3 python3-pip - pip3 install --upgrade pip - pip3 install pytest build: commands: - echo 'Running Python Tests' - | codebuild-tests-run \ --test-command 'python -m pytest' \ --files-search "codebuild-glob-search 'tests/test_*.py'" \ --sharding-strategy 'equal-distribution' post_build: commands: - echo "Test execution completed"

The following is sample of a buildspec.yml that shows parallel test execution with Pytest on an Windows platform:

version: 0.2 batch: fast-fail: false build-fanout: parallelism: 5 ignore-failure: false phases: install: commands: - echo 'Installing Python dependencies' - pip install pytest pre_build: commands: - echo 'prebuild' build: commands: - echo 'Running pytest' - | & codebuild-tests-run ` --test-command 'pytest @("$env:CODEBUILD_CURRENT_SHARD_FILES" -split \"`r?`n\")' ` --files-search "codebuild-glob-search '**/test_*.py' '**/*_test.py'" ` --sharding-strategy 'equal-distribution' post_build: commands: - echo "Test execution completed"

In the above example, CODEBUILD_CURRENT_SHARD_FILES environment variable is used to fetch test files assigned to current shard and passed as array to pytest command.