Skip to content

Commit d3e7161

Browse files
committed
chore(ci): split emulation tests per architecture
1 parent 97da904 commit d3e7161

File tree

4 files changed

+50
-16
lines changed

4 files changed

+50
-16
lines changed

.github/workflows/test.yml

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
run: pipx run nox -s pylint -- --output-format=github
3232

3333
test:
34-
name: Test cibuildwheel on ${{ matrix.os }} (${{ matrix.python_version }})
34+
name: Test on ${{ matrix.os }} (${{ matrix.python_version }})
3535
needs: lint
3636
runs-on: ${{ matrix.os }}
3737
strategy:
@@ -125,19 +125,41 @@ jobs:
125125
run: |
126126
python ./bin/run_tests.py --run-podman
127127
128-
test-emulated:
129-
name: Test emulated cibuildwheel using qemu
128+
emulated-archs:
129+
name: Get qemu emulated architectures
130130
needs: lint
131131
runs-on: ubuntu-latest
132-
timeout-minutes: 180
132+
outputs:
133+
archs: ${{ steps.archs.outputs.archs }}
133134
steps:
134135
- uses: actions/checkout@v4
135136
- uses: actions/setup-python@v5
136137
with:
137138
python-version: "3.x"
138139
- name: Install dependencies
140+
run: python -m pip install ".[test]"
141+
- name: Get qemu emulated architectures
142+
id: archs
139143
run: |
140-
python -m pip install ".[test]"
144+
OUTPUT=$(python -c "from json import dumps; from test.utils import EMULATED_ARCHS; print(dumps(EMULATED_ARCHS))")
145+
echo "${OUTPUT}"
146+
echo "archs=${OUTPUT}" >> "$GITHUB_OUTPUT"
147+
148+
test-emulated:
149+
name: Test Linux ${{ matrix.arch }} using qemu
150+
needs: emulated-archs
151+
runs-on: ubuntu-latest
152+
timeout-minutes: 180
153+
strategy:
154+
matrix:
155+
arch: ${{ fromJSON(needs.emulated-archs.outputs.archs) }}
156+
steps:
157+
- uses: actions/checkout@v4
158+
- uses: actions/setup-python@v5
159+
with:
160+
python-version: "3.x"
161+
- name: Install dependencies
162+
run: python -m pip install ".[test]"
141163

142164
- name: Set up QEMU
143165
id: qemu
@@ -146,5 +168,4 @@ jobs:
146168
platforms: all
147169

148170
- name: Run the emulation tests
149-
run: |
150-
pytest --run-emulation test/test_emulation.py
171+
run: pytest --run-emulation ${{ matrix.arch }} test/test_emulation.py

test/conftest.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@
88

99
from cibuildwheel.util import detect_ci_provider
1010

11-
from .utils import platform
11+
from .utils import EMULATED_ARCHS, platform
1212

1313

1414
def pytest_addoption(parser) -> None:
1515
parser.addoption(
16-
"--run-emulation", action="store_true", default=False, help="run emulation tests"
16+
"--run-emulation",
17+
action="store",
18+
default=None,
19+
help="run emulation tests",
20+
choices=("all", *EMULATED_ARCHS),
1721
)
1822
parser.addoption("--run-podman", action="store_true", default=False, help="run podman tests")
1923
parser.addoption(

test/test_emulation.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import itertools
34
import subprocess
45

56
import pytest
@@ -18,9 +19,13 @@ def test_spam():
1819

1920

2021
def test(tmp_path, request):
21-
if not request.config.getoption("--run-emulation"):
22+
archs = request.config.getoption("--run-emulation")
23+
if archs is None:
2224
pytest.skip("needs --run-emulation option to run")
2325

26+
if archs == "all":
27+
archs = " ".join(utils.EMULATED_ARCHS)
28+
2429
project_dir = tmp_path / "project"
2530
project_with_a_test.generate(project_dir)
2631

@@ -30,15 +35,14 @@ def test(tmp_path, request):
3035
add_env={
3136
"CIBW_TEST_REQUIRES": "pytest",
3237
"CIBW_TEST_COMMAND": "pytest {project}/test",
33-
"CIBW_ARCHS": "aarch64 ppc64le s390x",
38+
"CIBW_ARCHS": archs,
3439
},
3540
)
3641

3742
# also check that we got the right wheels
38-
expected_wheels = (
39-
utils.expected_wheels("spam", "0.1.0", machine_arch="aarch64")
40-
+ utils.expected_wheels("spam", "0.1.0", machine_arch="ppc64le")
41-
+ utils.expected_wheels("spam", "0.1.0", machine_arch="s390x")
43+
expected_wheels = itertools.chain.from_iterable(
44+
utils.expected_wheels("spam", "0.1.0", machine_arch=arch, single_arch=True)
45+
for arch in archs.split(" ")
4246
)
4347
assert set(actual_wheels) == set(expected_wheels)
4448

test/utils.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@
1313
from tempfile import TemporaryDirectory
1414
from typing import Final
1515

16+
from cibuildwheel.architecture import Architecture
1617
from cibuildwheel.util import CIBW_CACHE_PATH
1718

19+
EMULATED_ARCHS: Final[list[str]] = sorted(
20+
arch.value for arch in (Architecture.all_archs("linux") - Architecture.auto_archs("linux"))
21+
)
1822
SINGLE_PYTHON_VERSION: Final[tuple[int, int]] = (3, 12)
1923

2024
platform: str
@@ -154,6 +158,7 @@ def expected_wheels(
154158
python_abi_tags=None,
155159
include_universal2=False,
156160
single_python=False,
161+
single_arch=False,
157162
):
158163
"""
159164
Returns a list of expected wheels from a run of cibuildwheel.
@@ -237,7 +242,7 @@ def expected_wheels(
237242
if platform == "linux":
238243
architectures = [arch_name_for_linux(machine_arch)]
239244

240-
if machine_arch == "x86_64":
245+
if machine_arch == "x86_64" and not single_arch:
241246
architectures.append("i686")
242247

243248
if len(manylinux_versions) > 0:

0 commit comments

Comments
 (0)