Skip to content

Commit 2ecccba

Browse files
committed
TEST: Clear registry before and after every doctest
1 parent 1350d57 commit 2ecccba

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

sdcflows/conftest.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import nibabel
2828
import pytest
2929
from bids.layout import BIDSLayout
30+
from .fieldmaps import clear_registry
3031

3132
# disable ET
3233
os.environ['NO_ET'] = '1'
@@ -59,18 +60,27 @@ def pytest_report_header(config):
5960

6061

6162
@pytest.fixture(autouse=True)
62-
def add_np(doctest_namespace):
63-
doctest_namespace["np"] = numpy
64-
doctest_namespace["nb"] = nibabel
65-
doctest_namespace["os"] = os
66-
doctest_namespace["Path"] = Path
67-
doctest_namespace["layouts"] = layouts
68-
for key, val in list(layouts.items()):
69-
doctest_namespace[key] = Path(val.root)
70-
71-
doctest_namespace["dsA_dir"] = data_dir / "dsA"
72-
doctest_namespace["dsB_dir"] = data_dir / "dsB"
73-
doctest_namespace["dsC_dir"] = data_dir / "dsC"
63+
def doctest_fixture(doctest_namespace, request):
64+
doctest_plugin = request.config.pluginmanager.getplugin("doctest")
65+
if isinstance(request.node, doctest_plugin.DoctestItem):
66+
doctest_namespace.update(
67+
np=numpy,
68+
nb=nibabel,
69+
os=os,
70+
Path=Path,
71+
layouts=layouts,
72+
dsA_dir=data_dir / "dsA",
73+
dsB_dir=data_dir / "dsB",
74+
dsC_dir=data_dir / "dsC",
75+
)
76+
doctest_namespace.update((key, Path(val.root)) for key, val in layouts.items())
77+
78+
# Start every doctest clean, and clean up after ourselves
79+
clear_registry()
80+
yield
81+
clear_registry()
82+
else:
83+
yield
7484

7585

7686
@pytest.fixture

0 commit comments

Comments
 (0)