

As traduções são geradas por tradução automática. Em caso de conflito entre o conteúdo da tradução e da versão original em inglês, a versão em inglês prevalecerá.

# Configurar testes em paralelo com o Pytest
<a name="sample-parallel-test-python"></a>

Veja a seguir uma amostra de um `buildspec.yml` que mostra a execução de testes em paralelo com o Pytest em uma plataforma Ubuntu:

```
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"
```

Veja a seguir uma amostra de um `buildspec.yml` que mostra a execução de testes em paralelo com o Pytest em uma plataforma Windows:

```
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"
```

No exemplo acima, a variável de ambiente `CODEBUILD_CURRENT_SHARD_FILES` é usada para buscar arquivos de teste atribuídos ao fragmento atual e passados como matriz para o comando pytest.