forked from fitbenchmarking/fitbenchmarking
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconftest.py
47 lines (38 loc) · 1.22 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
import pytest
# set choices for --test-type
test_choices = ["all", "default", "matlab"]
def pytest_addoption(parser):
"""
Command line input function which requires 'all', 'default' or 'matlab'
as an input
"""
parser.addoption(
"--test-type",
action="store",
default="all",
type=str,
choices=test_choices,
)
def pytest_configure(config):
"""
Sets variable `pytest.test_type` to be used within testing
"""
pytest.test_type = config.getoption("--test-type")
def run_for_test_types(TEST_TYPE, *test_types):
"""
Sets decorator that specifies the test types for which a
class/function should be skipped
:param TEST_TYPE: the test type selected by the user
:type TEST_TYPE: str
:param test_types: the test types for which the class/function
should be run
:type test_types: str
:return: decorator that specifies if class/function should be
skipped based on chosen TEST_TYPE
:rtype: callable
"""
to_skip = [type for type in test_choices if type not in test_types]
return pytest.mark.skipif(
TEST_TYPE in to_skip,
reason="Tests can't be run with selected test type",
)