使用 Django 配置并行测试 - Amazon CodeBuild
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

使用 Django 配置并行测试

以下 buildspec.yml 示例显示在 Ubuntu 平台上使用 Django 并行执行测试:

version: 0.2 batch: fast-fail: false build-fanout: parallelism: 5 phases: install: commands: - echo 'Installing Python dependencies' - sudo yum install -y python3 python3-pip - python3 -m ensurepip --upgrade - python3 -m pip install django pre_build: commands: - echo 'Prebuild' build: commands: - echo 'Running Django Tests' - | codebuild-tests-run \ --test-command 'python3 manage.py test $(echo "$CODEBUILD_CURRENT_SHARD_FILES" | sed -E "s/\//__/g; s/\.py$//; s/__/./g")' \ --files-search "codebuild-glob-search '**/tests/*test_*.py'" \ --sharding-strategy 'equal-distribution' post_build: commands: - echo 'Test execution completed'

上面的示例显示了环境变量 CODEBUILD_CURRENT_SHARD_FILES 的用法。此处,CODEBUILD_CURRENT_SHARD_FILES 用于获取 Django 支持的点符号文件路径。如上所示,在双引号内使用 CODEBUILD_CURRENT_SHARD_FILES