Enable unit testing for model evaluation component (#3575)

* Workflow for model eval unit tests.

* Make conda verbose.

* Force CPU installation for torch related packages.

* Add pytest as dependent package.

* Install pytest-xdist.

* Modify conda dependencies in workflow configuration.

* Escape slashes in sed command.

* Properly append two lines to conda env file.

* Cosmetics.
This commit is contained in:
rdondera-microsoft 2024-11-11 15:52:40 -08:00 коммит произвёл GitHub
Родитель 3c893e2226
Коммит a390ade08f
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
1 изменённых файлов: 61 добавлений и 0 удалений

61
.github/workflows/training-model-eval-unittests.yaml поставляемый Normal file
Просмотреть файл

@ -0,0 +1,61 @@
name: training-model-eval-unittests
on:
pull_request:
branches:
- main
paths:
- assets/training/model_evaluation/**
- .github/workflows/training-model-eval-unittests.yaml
workflow_dispatch:
env:
conda_env_prefix: /opt/conda/envs/model_eval
model_eval_unittests_dir: assets/training/model_evaluation/tests
model_eval_conda_yaml: assets/training/model_evaluation/environment/context/conda.yaml
pytest_reports: pytest-reports
jobs:
run_unit_tests:
name: Run
runs-on: ubuntu-latest
permissions:
# Required for EnricoMi/publish-unit-test-result-action
checks: write
issues: read
pull-requests: write
steps:
- name: Clone branch
uses: actions/checkout@v3
- name: Use Python 3.10 or newer
uses: actions/setup-python@v4
with:
python-version: '>=3.10'
- name: Create conda env
run: |
set -ex
apt-get update && apt-get upgrade && apt-get install -y build-essential
echo $conda_env_prefix
sed -i 's/- pip:/- pip:\n - --extra-index-url https:\/\/download.pytorch.org\/whl\/cpu/' $model_eval_conda_yaml
sed -i 's/=={{latest-pypi-version}}//g' $model_eval_conda_yaml
sed -i 's/=={{latest-pypi-version:pre}}//g' $model_eval_conda_yaml
echo " - pytest" >> $model_eval_conda_yaml
echo " - pytest-xdist" >> $model_eval_conda_yaml
cat $model_eval_conda_yaml
conda env create -p $conda_env_prefix -f $model_eval_conda_yaml
echo "conda env successfully created at $conda_env_prefix"
conda list -p $conda_env_prefix
- name: Execute tests
run: conda run -p $conda_env_prefix python -m pytest $model_eval_unittests_dir --tb=native --junitxml=$pytest_reports/test-result.xml -x -n 1 -ra --show-capture=no
- name: Publish test results
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
check_name: Test Results for ${{ github.workflow }}
junit_files: ${{ env.pytest_reports }}/**/*.xml