6
6
import time
7
7
from src .wrappers .OsipiBase import OsipiBase
8
8
#run using python -m pytest from the root folder
9
- import matlab .engine
10
9
11
- eng = matlab .engine .start_matlab ()
10
+
11
+ eng = None
12
+
13
+ def pytest_addoption (parser ):
14
+ parser .addoption (
15
+ "--with-matlab" , action = "store_true" , default = False , help = "Run MATLAB-dependent tests"
16
+ )
17
+
18
+ @pytest .hookimpl
19
+ def pytest_configure (config ):
20
+ global eng
21
+ if config .getoption ("--with-matlab" ):
22
+ import matlab .engine
23
+ eng = matlab .engine .start_matlab ()
24
+
12
25
13
26
def signal_helper (signal ):
14
27
signal = np .asarray (signal )
@@ -61,7 +74,10 @@ def data_ivim_fit_saved():
61
74
skiptime = True
62
75
first = False # this will only work for 1 algorithm... If two algorithms use fail_first_time, the second will not see it is the first time.
63
76
if algorithm_dict .get ("requieres_matlab" , {}) == True :
64
- kwargs = {** kwargs ,'eng' : eng }
77
+ if eng is None :
78
+ continue
79
+ else :
80
+ kwargs = {** kwargs ,'eng' : eng }
65
81
yield name , bvals , data , algorithm , xfail , kwargs , tolerances , skiptime
66
82
67
83
@pytest .mark .parametrize ("name, bvals, data, algorithm, xfail, kwargs, tolerances, skiptime" , data_ivim_fit_saved ())
@@ -100,7 +116,7 @@ def to_list_if_needed(value):
100
116
assert elapsed_time < 0.5 , f"Algorithm { name } took { elapsed_time } seconds, which is longer than 2 second to fit per voxel" #less than 0.5 seconds per voxel
101
117
102
118
103
- def algorithms ():
119
+ def algorithmlist ():
104
120
# Find the algorithms from algorithms.json
105
121
file = pathlib .Path (__file__ )
106
122
algorithm_path = file .with_name ('algorithms.json' )
@@ -111,10 +127,13 @@ def algorithms():
111
127
algorithm_dict = algorithm_information .get (algorithm , {})
112
128
args = {}
113
129
if algorithm_dict .get ("requieres_matlab" , {}) == True :
114
- args ['eng' ] = eng
130
+ if eng is None :
131
+ continue
132
+ else :
133
+ kwargs = {** kwargs , 'eng' : eng }
115
134
yield algorithm , args
116
135
117
- @pytest .mark .parametrize ("algorithm, args" , algorithms ())
136
+ @pytest .mark .parametrize ("algorithm, args" , algorithmlist ())
118
137
def test_default_bounds_and_initial_guesses (algorithm , args ):
119
138
fit = OsipiBase (algorithm = algorithm ,** args )
120
139
#assert fit.bounds is not None, f"For {algorithm}, there is no default fit boundary"
@@ -159,7 +178,10 @@ def bound_input():
159
178
kwargs = algorithm_dict .get ("options" , {})
160
179
tolerances = algorithm_dict .get ("tolerances" , {})
161
180
if algorithm_dict .get ("requieres_matlab" , {}) == True :
162
- kwargs = {** kwargs ,'eng' : eng }
181
+ if eng is None :
182
+ continue
183
+ else :
184
+ kwargs = {** kwargs , 'eng' : eng }
163
185
yield name , bvals , data , algorithm , xfail , kwargs , tolerances
164
186
165
187
0 commit comments