forked from meltano/sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconftest.py
54 lines (38 loc) · 1.39 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
"""Top level test fixtures."""
from __future__ import annotations
import os
import pathlib
import platform
import shutil
import pytest
from _pytest.config import Config
SYSTEMS = {"linux", "darwin", "windows"}
pytest_plugins = ("singer_sdk.testing.pytest_plugin",)
def pytest_collection_modifyitems(config: Config, items: list[pytest.Item]):
rootdir = pathlib.Path(config.rootdir)
for item in items:
rel_path = pathlib.Path(item.fspath).relative_to(rootdir)
# Mark all tests under tests/external*/ as 'external'
if rel_path.parts[1].startswith("external"):
item.add_marker("external")
def pytest_runtest_setup(item):
supported_systems = SYSTEMS.intersection(mark.name for mark in item.iter_markers())
system = platform.system().lower()
if supported_systems and system not in supported_systems:
pytest.skip(f"cannot run on platform {system}")
@pytest.fixture(scope="class")
def outdir() -> str:
"""Create a temporary directory for cookiecutters and target output."""
name = ".output/"
try:
os.mkdir(name)
except FileExistsError:
# Directory already exists
shutil.rmtree(name)
os.mkdir(name)
yield name
shutil.rmtree(name)
@pytest.fixture(scope="session")
def snapshot_dir() -> pathlib.Path:
"""Return the path to the snapshot directory."""
return pathlib.Path("tests/snapshots/")