-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
Copy pathtest-linux.yml
225 lines (200 loc) · 8.16 KB
/
test-linux.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
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'))