Skip to content

Commit

Permalink
OPT(TST): cache ds005 collection and return a clone upon invocation
Browse files Browse the repository at this point in the history
Creating a collection apparently is more expensive.
Clone() is needed since some tests do modification inplace. If they did not
it was possible to declare this fixture as (scope="module"). So we need to return
a clone each time.  This causes full run time of 9 sec vs 30 sec.
  • Loading branch information
yarikoptic committed Mar 6, 2019
1 parent 690f78d commit a06773a
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions bids/analysis/tests/test_transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,24 @@
NRUNS = 3
SCAN_LENGTH = 480

cached_collections = {}


@pytest.fixture
def collection():
layout_path = join(get_test_data_path(), 'ds005')
layout = BIDSLayout(layout_path)
collection = layout.get_collections('run', types=['events'],
scan_length=SCAN_LENGTH,
merge=True,
sampling_rate=10,
subject=SUBJECTS
)
return collection
if 'ds005' not in cached_collections:
layout_path = join(get_test_data_path(), 'ds005')
layout = BIDSLayout(layout_path)
cached_collections['ds005'] = layout.get_collections(
'run',
types=['events'],
scan_length=SCAN_LENGTH,
merge=True,
sampling_rate=10,
subject=SUBJECTS
)
# Always return a clone!
return cached_collections['ds005'].clone()


@pytest.fixture
Expand Down

0 comments on commit a06773a

Please sign in to comment.