forked from SpikeInterface/spikeinterface
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconftest.py
41 lines (30 loc) · 1.25 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
import pytest
import shutil
from pathlib import Path
# define marks
mark_names = ["core", "extractors", "preprocessing", "postprocessing",
"sorters", "qualitymetrics", "comparison", "curation",
"widgets", "exporters", "sortingcomponents"]
# define global test folder
def pytest_sessionstart(session):
# setup_stuff
pytest.global_test_folder = Path(__file__).parent / "test_folder"
if pytest.global_test_folder.is_dir():
shutil.rmtree(pytest.global_test_folder)
pytest.global_test_folder.mkdir()
for mark_name in mark_names:
(pytest.global_test_folder / mark_name).mkdir()
def pytest_collection_modifyitems(config, items):
# python 3.4/3.5 compat: rootdir = pathlib.Path(str(config.rootdir))
rootdir = Path(config.rootdir)
for item in items:
rel_path = Path(item.fspath).relative_to(rootdir)
for mark_name in mark_names:
if f"/{mark_name}/" in str(rel_path):
mark = getattr(pytest.mark, mark_name)
item.add_marker(mark)
def pytest_sessionfinish(session, exitstatus):
# teardown_stuff only if tests passed
if exitstatus == 0:
if pytest.global_test_folder.is_dir():
shutil.rmtree(pytest.global_test_folder)