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:
co-authored by
Joe Rickerby
parent
7e5810c550
commit
4d37797aa6
@@ -717,12 +717,15 @@ def build(options: Options, tmp_path: Path) -> None:
|
|||||||
|
|
||||||
if build_options.test_sources:
|
if build_options.test_sources:
|
||||||
test_cwd = identifier_tmp_dir / "test_cwd"
|
test_cwd = identifier_tmp_dir / "test_cwd"
|
||||||
test_cwd.mkdir(exist_ok=True)
|
# only create test_cwd if it doesn't already exist - it
|
||||||
copy_test_sources(
|
# may have been created during a previous `testing_arch`
|
||||||
build_options.test_sources,
|
if not test_cwd.exists():
|
||||||
build_options.package_dir,
|
test_cwd.mkdir()
|
||||||
test_cwd,
|
copy_test_sources(
|
||||||
)
|
build_options.test_sources,
|
||||||
|
build_options.package_dir,
|
||||||
|
test_cwd,
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
# There are no test sources. Run the tests in the project directory.
|
# There are no test sources. Run the tests in the project directory.
|
||||||
test_cwd = Path(".").resolve()
|
test_cwd = Path(".").resolve()
|
||||||
|
|||||||
@@ -8,6 +8,11 @@ import pytest
|
|||||||
from . import test_projects, utils
|
from . import test_projects, utils
|
||||||
|
|
||||||
basic_project = test_projects.new_c_project()
|
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 = {
|
ALL_MACOS_WHEELS = {
|
||||||
*utils.expected_wheels("spam", "0.1.0", machine_arch="x86_64"),
|
*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])
|
@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":
|
if utils.platform != "macos":
|
||||||
pytest.skip("this test is only relevant to macos")
|
pytest.skip("this test is only relevant to macos")
|
||||||
if get_xcode_version() < (12, 2):
|
if get_xcode_version() < (12, 2):
|
||||||
@@ -64,9 +83,9 @@ def test_cross_compiled_test(tmp_path, capfd, build_universal2):
|
|||||||
project_dir,
|
project_dir,
|
||||||
add_env={
|
add_env={
|
||||||
"CIBW_BUILD": "cp310-*" if build_universal2 else "*p310-*",
|
"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_ARCHS": "universal2" if build_universal2 else "x86_64 arm64",
|
||||||
"CIBW_BUILD_VERBOSITY": "3",
|
"CIBW_BUILD_VERBOSITY": "3",
|
||||||
|
**test_config,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user