Correct handling of test_sources on universal macOS builds. (#2284)

* Correct handling of test_sources on universal macOS builds.

* Make the test sources modifications macOS only.

* Don't use unittest discovery - that needs an actual test.

* Add comment explaining test source creation

Co-authored-by: Joe Rickerby <joerick@mac.com>

* Simplify dict usage.

---------

Co-authored-by: Joe Rickerby <joerick@mac.com>
This commit is contained in:
Russell Keith-Magee
2025-02-26 09:13:09 +00:00
committed by GitHub
co-authored by Joe Rickerby
parent 7e5810c550
commit 4d37797aa6
2 changed files with 30 additions and 8 deletions
+9 -6
View File
@@ -717,12 +717,15 @@ def build(options: Options, tmp_path: Path) -> None:
if build_options.test_sources:
test_cwd = identifier_tmp_dir / "test_cwd"
test_cwd.mkdir(exist_ok=True)
copy_test_sources(
build_options.test_sources,
build_options.package_dir,
test_cwd,
)
# only create test_cwd if it doesn't already exist - it
# may have been created during a previous `testing_arch`
if not test_cwd.exists():
test_cwd.mkdir()
copy_test_sources(
build_options.test_sources,
build_options.package_dir,
test_cwd,
)
else:
# There are no test sources. Run the tests in the project directory.
test_cwd = Path(".").resolve()
+21 -2
View File
@@ -8,6 +8,11 @@ import pytest
from . import test_projects, utils
basic_project = test_projects.new_c_project()
basic_project.files["tests/test_suite.py"] = r"""
import platform
print("running tests on " + platform.machine())
"""
ALL_MACOS_WHEELS = {
*utils.expected_wheels("spam", "0.1.0", machine_arch="x86_64"),
@@ -51,7 +56,21 @@ def test_cross_compiled_build(tmp_path):
@pytest.mark.parametrize("build_universal2", [False, True])
def test_cross_compiled_test(tmp_path, capfd, build_universal2):
@pytest.mark.parametrize(
"test_config",
[
# Run the test suite in the project folder
{
"CIBW_TEST_COMMAND": '''python -c "import platform; print('running tests on ' + platform.machine())"''',
},
# Nominate the set of test sources to copy
{
"CIBW_TEST_COMMAND": "python tests/test_suite.py",
"CIBW_TEST_SOURCES": "tests",
},
],
)
def test_cross_compiled_test(tmp_path, capfd, build_universal2, test_config):
if utils.platform != "macos":
pytest.skip("this test is only relevant to macos")
if get_xcode_version() < (12, 2):
@@ -64,9 +83,9 @@ def test_cross_compiled_test(tmp_path, capfd, build_universal2):
project_dir,
add_env={
"CIBW_BUILD": "cp310-*" if build_universal2 else "*p310-*",
"CIBW_TEST_COMMAND": '''python -c "import platform; print('running tests on ' + platform.machine())"''',
"CIBW_ARCHS": "universal2" if build_universal2 else "x86_64 arm64",
"CIBW_BUILD_VERBOSITY": "3",
**test_config,
},
)