-
Notifications
You must be signed in to change notification settings - Fork 2
/
conftest.py
92 lines (66 loc) · 2.32 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
"""Global pytest fixtures."""
import os
import pytest
from tackle.context import Source
from tackle.factory import new_context
from tackle.imports import import_native_providers
@pytest.fixture(scope='function', autouse=True)
def cd_cwd(request):
"""Change to current directory - default for all tests."""
os.chdir(request.fspath.dirname)
@pytest.fixture(scope='function')
def cd(request):
"""Change to a local directory from a test, usually a fixtures dir."""
def f(path: str | list):
if isinstance(path, list):
path = os.path.join(*path)
os.chdir(os.path.join(request.fspath.dirname, path))
return f
@pytest.fixture(scope='function')
def cd_fixtures(cd):
"""Change to current directories fixtures."""
cd('fixtures')
@pytest.fixture(scope='function')
def base_dir():
"""Path to base of repo."""
return os.path.abspath(os.path.dirname(__file__))
@pytest.fixture(scope='function')
def base_hooks_dir(base_dir):
"""Path to base of repo."""
return os.path.join(base_dir, '.hooks')
@pytest.fixture(scope='function')
def cd_base_dir(monkeypatch, base_dir):
"""Change to the current directory."""
monkeypatch.chdir(base_dir)
@pytest.fixture()
def context(mocker):
"""An empty context - no source."""
mocker.patch(
'tackle.factory.new_source',
return_value=Source(),
autospec=True,
)
return new_context()
@pytest.fixture(scope='session', autouse=True)
def patch_native_provider_import(session_mocker):
"""
Importing the native providers is expensive and needs to be done on startup so to
avoid this we patch it and auto-use the value which is always the same.
"""
mock = session_mocker.patch(
'tackle.factory.import_native_providers',
return_value=import_native_providers(),
)
yield mock
def pytest_addoption(parser):
parser.addoption(
"--skip-slow", action="store_true", default=False, help="skip slow tests"
)
def pytest_configure(config):
config.addinivalue_line("markers", "slow: mark test as slow to run")
def pytest_collection_modifyitems(config, items):
if config.getoption("--skip-slow"):
skip_slow = pytest.mark.skip(reason="skipped slow test")
for item in items:
if "slow" in item.keywords:
item.add_marker(skip_slow)