forked from ddmms/ml-peg
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
54 lines (43 loc) · 1.6 KB
/
conftest.py
File metadata and controls
54 lines (43 loc) · 1.6 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
53
54
"""
Configure pytest.
Based on https://docs.pytest.org/en/latest/example/simple.html.
"""
from __future__ import annotations
import pytest
from ml_peg.models import models
def pytest_addoption(parser):
"""Add flag to run tests for extra MLIPs."""
parser.addoption(
"--run-slow",
action="store_true",
default=False,
help="Run slow benchmarks",
)
parser.addoption(
"--run-very-slow",
action="store_true",
default=False,
help="Run very slow benchmarks",
)
parser.addoption(
"--models",
action="store",
default=None,
help="MLIPs, in comma-separated list. Default is all models",
)
def pytest_configure(config):
"""Configure pytest to custom markers and CLI inputs."""
# Create custom marker for slow tests
config.addinivalue_line("markers", "slow: mark test as slow calculations")
config.addinivalue_line("markers", "very_slow: mark test as very slow calculations")
# Set current models from CLI input
models.current_models = config.getoption("--models")
def pytest_collection_modifyitems(config, items):
"""Skip tests if marker applied to unit tests."""
skip_slow = pytest.mark.skip(reason="need --run-slow option to run")
skip_very_slow = pytest.mark.skip(reason="need --run-very-slow option to run")
for item in items:
if "very_slow" in item.keywords and not config.getoption("--run-very-slow"):
item.add_marker(skip_very_slow)
elif "slow" in item.keywords and not config.getoption("--run-slow"):
item.add_marker(skip_slow)