diff --git a/unit_test/main_options_test.py b/unit_test/main_options_test.py index 1914f550..90935fe8 100644 --- a/unit_test/main_options_test.py +++ b/unit_test/main_options_test.py @@ -6,7 +6,7 @@ from cibuildwheel.__main__ import main from cibuildwheel.environment import ParsedEnvironment from cibuildwheel.util import BuildSelector -from main_util_fixtures import mock_protection, platform, intercepted_build_args +from main_util_fixtures import mock_protection, fake_project_dir, platform, intercepted_build_args diff --git a/unit_test/main_platform_test.py b/unit_test/main_platform_test.py index 101d3c4f..3de3be29 100644 --- a/unit_test/main_platform_test.py +++ b/unit_test/main_platform_test.py @@ -4,7 +4,7 @@ import sys from cibuildwheel.__main__ import main -from main_util_fixtures import MOCK_PROJECT_DIR, mock_protection, platform, intercepted_build_args +from main_util_fixtures import MOCK_PROJECT_DIR, mock_protection, fake_project_dir, platform, intercepted_build_args def test_unknown_platform_non_ci(monkeypatch, capsys): diff --git a/unit_test/main_util_fixtures.py b/unit_test/main_util_fixtures.py index ae7bd006..8bc80d87 100644 --- a/unit_test/main_util_fixtures.py +++ b/unit_test/main_util_fixtures.py @@ -17,6 +17,11 @@ MOCK_PROJECT_DIR = 'some_project_dir' @pytest.fixture(autouse=True) def mock_protection(monkeypatch): + ''' + Ensure that a unit test will never actually run a cibuildwheel 'build' + function, which shouldn't be run on a developer's machine + ''' + def fail_on_call(*args, **kwargs): raise RuntimeError("This should never be called") @@ -25,7 +30,21 @@ def mock_protection(monkeypatch): monkeypatch.setattr(windows, 'build', fail_on_call) monkeypatch.setattr(linux, 'build', fail_on_call) monkeypatch.setattr(macos, 'build', fail_on_call) - monkeypatch.setattr(os.path, 'exists', lambda x: True) + +@pytest.fixture(autouse=True) +def fake_project_dir(monkeypatch): + ''' + Monkey-patch enough for the main() function to run + ''' + + real_os_path_exists = os.path.exists + def mock_os_path_exists(path): + if path == os.path.join(MOCK_PROJECT_DIR, 'setup.py'): + return True + else: + return real_os_path_exists(path) + + monkeypatch.setattr(os.path, 'exists', mock_os_path_exists) monkeypatch.setattr(sys, 'argv', ['cibuildwheel', MOCK_PROJECT_DIR])