diff --git a/cibuildwheel/macos.py b/cibuildwheel/macos.py index e7347115..904bc3f1 100644 --- a/cibuildwheel/macos.py +++ b/cibuildwheel/macos.py @@ -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() diff --git a/test/test_macos_archs.py b/test/test_macos_archs.py index 53d90d19..8450bdd9 100644 --- a/test/test_macos_archs.py +++ b/test/test_macos_archs.py @@ -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, }, )