Files
cibuildwheel/unit_test/conftest.py
T

44 lines
1.2 KiB
Python
Raw Normal View History

2021-10-12 02:05:47 +01:00
import sys
from pathlib import Path
2020-06-26 21:37:02 +01:00
import pytest
2021-10-12 02:05:47 +01:00
MOCK_PACKAGE_DIR = Path("some_package_dir")
2020-06-26 21:37:02 +01:00
def pytest_addoption(parser):
2021-04-30 17:56:34 -04:00
parser.addoption("--run-docker", action="store_true", default=False, help="run docker tests")
2020-06-26 21:37:02 +01:00
def pytest_configure(config):
config.addinivalue_line("markers", "docker: mark test requiring docker to run")
2020-06-26 21:37:02 +01:00
def pytest_collection_modifyitems(config, items):
if config.getoption("--run-docker"):
# --run-docker given in cli: do not skip docker tests
2020-06-26 21:37:02 +01:00
return
skip_docker = pytest.mark.skip(reason="need --run-docker option to run")
2020-06-26 21:37:02 +01:00
for item in items:
if "docker" in item.keywords:
item.add_marker(skip_docker)
2021-10-12 02:05:47 +01:00
@pytest.fixture
def fake_package_dir(monkeypatch):
"""
Monkey-patch enough for the main() function to run
"""
real_path_exists = Path.exists
def mock_path_exists(path):
2022-04-26 22:21:27 -04:00
if str(path).endswith(str(MOCK_PACKAGE_DIR / "setup.py")):
2021-10-12 02:05:47 +01:00
return True
else:
return real_path_exists(path)
args = ["cibuildwheel", str(MOCK_PACKAGE_DIR)]
monkeypatch.setattr(Path, "exists", mock_path_exists)
monkeypatch.setattr(sys, "argv", args)
return args