Skip to content

Commit 5f695b8

Browse files
committed
TEST: Simplify data/environment fixtures
1 parent 325080e commit 5f695b8

File tree

2 files changed

+16
-26
lines changed

2 files changed

+16
-26
lines changed

nibabel/tests/test_data.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,19 @@
1919

2020
import pytest
2121

22-
from .test_environment import (with_environment,
23-
DATA_KEY,
24-
USER_KEY)
22+
from .test_environment import with_environment, DATA_KEY, USER_KEY
2523

2624

27-
@pytest.fixture()
25+
@pytest.fixture
2826
def with_nimd_env(request, with_environment):
2927
DATA_FUNCS = {}
3028
DATA_FUNCS['home_dir_func'] = nibd.get_nipy_user_dir
3129
DATA_FUNCS['sys_dir_func'] = nibd.get_nipy_system_dir
3230
DATA_FUNCS['path_func'] = nibd.get_data_path
33-
34-
def teardown_data_env():
35-
nibd.get_nipy_user_dir = DATA_FUNCS['home_dir_func']
36-
nibd.get_nipy_system_dir = DATA_FUNCS['sys_dir_func']
37-
nibd.get_data_path = DATA_FUNCS['path_func']
38-
39-
request.addfinalizer(teardown_data_env)
31+
yield
32+
nibd.get_nipy_user_dir = DATA_FUNCS['home_dir_func']
33+
nibd.get_nipy_system_dir = DATA_FUNCS['sys_dir_func']
34+
nibd.get_data_path = DATA_FUNCS['path_func']
4035

4136

4237
def test_datasource():

nibabel/tests/test_environment.py

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
USER_KEY = 'NIPY_USER_DIR'
1515

1616

17-
@pytest.fixture()
17+
@pytest.fixture
1818
def with_environment(request):
1919
"""Setup test environment for some functions that are tested
2020
in this module. In particular this functions stores attributes
@@ -24,20 +24,15 @@ def with_environment(request):
2424
"""
2525
GIVEN_ENV = {}
2626
GIVEN_ENV['env'] = env.copy()
27-
28-
29-
def teardown_environment():
30-
"""Restore things that were remembered by the setup_environment function
31-
"""
32-
orig_env = GIVEN_ENV['env']
33-
# Pull keys out into list to avoid altering dictionary during iteration,
34-
# causing python 3 error
35-
for key in list(env.keys()):
36-
if key not in orig_env:
37-
del env[key]
38-
env.update(orig_env)
39-
40-
request.addfinalizer(teardown_environment)
27+
yield
28+
"""Restore things that were remembered by the setup_environment function """
29+
orig_env = GIVEN_ENV['env']
30+
# Pull keys out into list to avoid altering dictionary during iteration,
31+
# causing python 3 error
32+
for key in list(env.keys()):
33+
if key not in orig_env:
34+
del env[key]
35+
env.update(orig_env)
4136

4237

4338
def test_nipy_home():

0 commit comments

Comments
 (0)