Skip to content

Commit

Permalink
Parallelise pytests in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
thesps committed Sep 30, 2021
1 parent 4564916 commit f32994a
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 16 deletions.
36 changes: 20 additions & 16 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
pytest:
image: gitlab-registry.cern.ch/fastmachinelearning/hls4ml-testing:0.2.base
stages:
- generate
- trigger
- test

generator:
stage: generate
image: python:3.7-alpine
tags:
- docker
before_script:
- source ~/.bashrc
- git submodule init
- git submodule update
- conda activate hls4ml-testing
- pip install .[profiling]
script:
- pip install pyyaml
script:
- cd test/pytest
- pytest -rA --cov-report xml --cov-report term --cov=hls4ml --junitxml=report.xml --randomly-seed=42 --randomly-dont-reorganize --randomly-dont-reset-seed
- python generate_ci_yaml.py
artifacts:
when: always
reports:
junit:
- test/pytest/report.xml
cobertura:
- test/pytest/coverage.xml
paths:
- test/pytest/hls4mlprj*.tar.gz
- test/pytest/pytests.yml

pytests:
stage: trigger
trigger:
include:
- artifact: test/pytest/pytests.yml
job: generator
strategy: depend
49 changes: 49 additions & 0 deletions test/pytest/generate_ci_yaml.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import yaml
import glob

base = """
.pytest:
stage: test
image: gitlab-registry.cern.ch/fastmachinelearning/hls4ml-testing:0.2.base
tags:
- docker
before_script:
- source ~/.bashrc
- if [ $EXAMPLEMODEL == 1 ]; then git submodule init; git submodule update; fi
- conda activate hls4ml-testing
- pip install .[profiling]
script:
- cd test/pytest
- pytest $PYTESTFILE -rA --cov-report xml --cov-report term --cov=hls4ml --junitxml=report.xml --randomly-seed=42 --randomly-dont-reorganize --randomly-dont-reset-seed
artifacts:
when: always
reports:
junit:
- test/pytest/report.xml
cobertura:
- test/pytest/coverage.xml
paths:
- test/pytest/hls4mlprj*.tar.gz
"""

template = """
pytest.{}:
extends: .pytest
variables:
PYTESTFILE: {}
EXAMPLEMODEL: {}
"""

def uses_example_model(test_filename):
with open(test_filename, 'r') as f:
content = f.read()
return 'example-models/' in content

yml = yaml.safe_load(base)
tests = glob.glob('test_*.py')
for test in tests:
name = test.replace('test_','').replace('.py','')
yml.update(yaml.safe_load(template.format(name, 'test_{}.py'.format(name), int(uses_example_model(test)))))

yamlfile = open('pytests.yml', 'w')
yaml.safe_dump(yml, yamlfile)

0 comments on commit f32994a

Please sign in to comment.