qiskit/.azure/test-linux.yml

226 lines
8.2 KiB
YAML

parameters:
- name: "pythonVersion"
type: string
displayName: "Version of Python to test"
- name: "testRust"
type: boolean
- name: "testImages"
type: boolean
- name: "installOptionals"
type: boolean
default: false
- name: "installFromSdist"
type: boolean
default: false
jobs:
- job: "Linux_Tests_Python${{ replace(parameters.pythonVersion, '.', '') }}"
displayName: "Test Linux Rust & Python ${{ parameters.pythonVersion }}"
pool: {vmImage: 'ubuntu-latest'}
variables:
QISKIT_SUPPRESS_PACKAGING_WARNINGS: Y
PIP_CACHE_DIR: $(Pipeline.Workspace)/.pip
QISKIT_TEST_CAPTURE_STREAMS: 1
HAVE_VISUAL_TESTS_RUN: false
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '${{ parameters.pythonVersion }}'
name: 'usePython'
displayName: 'Use Python ${{ parameters.pythonVersion }}'
- task: Cache@2
inputs:
key: 'stestr | "$(Agent.OS)" | "${{ parameters.pythonVersion }}" | "$(Build.BuildNumber)"'
restoreKeys: |
stestr | "$(Agent.OS)" | "${{ parameters.pythonVersion }}"
stestr | "$(Agent.OS)"
stestr
path: .stestr
displayName: "Cache stestr"
- ${{ if eq(parameters.testRust, true) }}:
# We need to avoid linking our crates into full Python extension libraries during Rust-only
# testing because Rust/PyO3 can't handle finding a static CPython interpreter.
- bash: cargo test --no-default-features
env:
# On Linux we link against `libpython` dynamically, but it isn't written into the rpath
# of the test executable (I'm not 100% sure why ---Jake). It's easiest just to forcibly
# include the correct place in the `dlopen` search path.
LD_LIBRARY_PATH: '$(usePython.pythonLocation)/lib:$LD_LIBRARY_PATH'
displayName: "Run Rust tests"
- bash: |
set -e
python -m pip install --upgrade pip setuptools wheel virtualenv
virtualenv test-job
displayName: "Prepare venv"
- ${{ if eq(parameters.installFromSdist, true) }}:
- bash: |
set -e
# Use stable Rust, rather than MSRV, to spot-check that stable builds properly.
rustup override set stable
source test-job/bin/activate
python -m pip install -U pip
python -m pip install -U build
python -m build --sdist .
python -m pip install -U \
-c constraints.txt \
-r requirements.txt \
-r requirements-dev.txt \
dist/qiskit-*.tar.gz
# Build and install both qiskit and qiskit-terra so that any optionals
# depending on `qiskit` will resolve correctly.
displayName: "Install Terra from sdist"
- ${{ if eq(parameters.installFromSdist, false) }}:
- bash: |
set -e
source test-job/bin/activate
python -m pip install -U \
-c constraints.txt \
-r requirements.txt \
-r requirements-dev.txt \
-e .
# Build and install both qiskit and qiskit-terra so that any optionals
# depending on `qiskit` will resolve correctly.
displayName: "Install Terra directly"
- ${{ if eq(parameters.installOptionals, true) }}:
- bash: |
set -e
source test-job/bin/activate
python -m pip install -r requirements-optional.txt -c constraints.txt
python -m pip check
displayName: "Install optional packages"
- bash: |
set -e
sudo apt-get update
sudo apt-get install -y graphviz
displayName: 'Install optional non-Python dependencies'
- bash: |
set -e
source test-job/bin/activate
python tools/report_numpy_state.py
mkdir -p /tmp/terra-tests
cp -r test /tmp/terra-tests/.
cp .stestr.conf /tmp/terra-tests/.
cp -r .stestr /tmp/terra-tests/. || :
pushd /tmp/terra-tests
export PYTHONHASHSEED=$(python -S -c "import random; print(random.randint(1, 4294967295))")
echo "PYTHONHASHSEED=$PYTHONHASHSEED"
stestr run
popd
env:
QISKIT_PARALLEL: FALSE
RUST_BACKTRACE: 1
displayName: 'Run Python tests'
- bash: |
set -e
source test-job/bin/activate
cp tools/subunit_to_junit.py /tmp/terra-tests/.
python -m pip install -U junitxml
pushd /tmp/terra-tests
mkdir -p junit
stestr last --subunit | ./subunit_to_junit.py -o junit/test-results.xml
pushd .stestr
ls | grep -P "^\d" | xargs -d "\n" rm -f
popd
popd
cp -r /tmp/terra-tests/junit .
cp -r /tmp/terra-tests/.stestr .
displayName: 'Generate results'
condition: succeededOrFailed()
- task: PublishTestResults@2
condition: succeededOrFailed()
inputs:
testResultsFiles: '**/test-*.xml'
testRunTitle: 'Test results for Linux Python ${{ parameters.pythonVersion }}'
- task: CopyFiles@2
inputs:
contents: '**/*.png'
targetFolder: $(Build.ArtifactStagingDirectory)
displayName: 'Copy images on test failure'
condition: failed()
- task: PublishBuildArtifacts@1
inputs:
pathtoPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: 'drop_linux'
displayName: 'Publish images on test failure'
condition: failed()
- ${{ if eq(parameters.testImages, true) }}:
- bash: |
set -e
virtualenv image_tests
image_tests/bin/python -m pip install -U \
-c constraints.txt \
-r requirements.txt \
-r requirements-dev.txt \
-r requirements-optional.txt \
-e .
sudo apt-get update
sudo apt-get install -y graphviz pandoc
image_tests/bin/pip check
displayName: 'Install dependencies'
- bash: |
echo "##vso[task.setvariable variable=HAVE_VISUAL_TESTS_RUN;]true"
image_tests/bin/python -m unittest discover -v test/visual
displayName: 'Run image test'
env:
# Needed to suppress a warning in jupyter-core 5.x by eagerly migrating to
# a new internal interface that will be the default in jupyter-core 6.x.
# This variable should become redundant on release of jupyter-core 6.
JUPYTER_PLATFORM_DIRS: 1
- task: ArchiveFiles@2
displayName: Archive visual test failure diffs
inputs:
rootFolderOrFile: 'test/visual/mpl/visual_test_failures'
includeRootFolder: false
archiveType: tar
archiveFile: '$(Build.ArtifactStagingDirectory)/visual_test_failures.tar.gz'
verbose: true
condition: and(failed(), eq(variables.HAVE_VISUAL_TESTS_RUN, 'true'))
- task: ArchiveFiles@2
displayName: Archive circuit results
inputs:
rootFolderOrFile: 'test/visual/mpl/circuit/circuit_results'
archiveType: tar
archiveFile: '$(Build.ArtifactStagingDirectory)/circuit_results.tar.gz'
verbose: true
condition: and(failed(), eq(variables.HAVE_VISUAL_TESTS_RUN, 'true'))
- task: ArchiveFiles@2
displayName: Archive graph results
inputs:
rootFolderOrFile: 'test/visual/mpl/graph/graph_results'
archiveType: tar
archiveFile: '$(Build.ArtifactStagingDirectory)/graph_results.tar.gz'
verbose: true
condition: and(failed(), eq(variables.HAVE_VISUAL_TESTS_RUN, 'true'))
- task: PublishBuildArtifacts@1
displayName: 'Publish image test failure diffs'
inputs:
pathtoPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: 'image_test_failure_img_diffs'
Parallel: true
ParallelCount: 8
condition: and(failed(), eq(variables.HAVE_VISUAL_TESTS_RUN, 'true'))