-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathconftest.py
More file actions
52 lines (40 loc) · 1.58 KB
/
conftest.py
File metadata and controls
52 lines (40 loc) · 1.58 KB
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
import os
import typing
from unittest.mock import patch
import py
import pytest
def _is_running_in_ci() -> bool:
return bool(os.environ.get("CI"))
def pytest_addoption(parser):
parser.addoption(
"--run-integration",
action="store_true",
default=True if _is_running_in_ci() else False,
help="Run integration tests (aka. download external resources)",
)
def pytest_configure(config):
config.addinivalue_line("markers", "integration: mark test as integration test (aka. download external resources)")
def pytest_collection_modifyitems(config, items):
if config.getoption("--run-integration"):
return
skip_integration = pytest.mark.skip(reason="need --run-integration option to run or CI env variable defined")
for item in items:
if "integration" in item.keywords:
item.add_marker(skip_integration)
@pytest.fixture
def ensure_download_possible(tmpdir: py.path.local) -> typing.Generator[None, None, None]:
with patch.dict(
os.environ,
{
# Patch PRE_COMMIT_HOME using a temporary directory to ensure that
# we do actually download the pointed JAR
"PRE_COMMIT_HOME": tmpdir.realpath().strpath,
},
), patch(
# Mock copyfileobj such that we don't really download all the content
# after all we do care only about being able to start receiving the file
# because it would be sufficient to prove that the path is correct
"language_formatters_pre_commit_hooks.utils.shutil.copyfileobj",
autospec=True,
):
yield