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.

Disclaimer:there is still some nasty "inplace" changes happening probably or
clone() being not sufficient.  For me
  python -m pytest -s -v bids/analysis/tests/test_transformations.py::test_{filter,replace}
causes test_replace to fail.
  • Loading branch information
yarikoptic committed Mar 6, 2019
1 parent 690f78d commit 3458ec6
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions bids/analysis/tests/test_transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,22 @@
NRUNS = 3
SCAN_LENGTH = 480

cached_collections = {}


@pytest.fixture
def collection():
if 'ds005' in cached_collections:
return cached_collections['ds005'].clone()
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
)
cached_collections['ds005'] = collection \
= layout.get_collections('run', types=['events'],
scan_length=SCAN_LENGTH,
merge=True,
sampling_rate=10,
subject=SUBJECTS
)
return collection


Expand Down

0 comments on commit 3458ec6

Please sign in to comment.