/
conftest.py
43 lines (31 loc) 路 1.17 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import sys
from pathlib import Path
import pytest
MOCK_PACKAGE_DIR = Path("some_package_dir")
def pytest_addoption(parser):
parser.addoption("--run-docker", action="store_true", default=False, help="run docker tests")
def pytest_configure(config):
config.addinivalue_line("markers", "docker: mark test requiring docker to run")
def pytest_collection_modifyitems(config, items):
if config.getoption("--run-docker"):
# --run-docker given in cli: do not skip docker tests
return
skip_docker = pytest.mark.skip(reason="need --run-docker option to run")
for item in items:
if "docker" in item.keywords:
item.add_marker(skip_docker)
@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):
if str(path).endswith(str(MOCK_PACKAGE_DIR / "setup.py")):
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