Skip to content

Commit

Permalink
TEST: Clear registry before and after every doctest
Browse files Browse the repository at this point in the history
  • Loading branch information
effigies committed Oct 3, 2024
1 parent 1350d57 commit 2ecccba
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions sdcflows/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import nibabel
import pytest
from bids.layout import BIDSLayout
from .fieldmaps import clear_registry

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


@pytest.fixture(autouse=True)
def add_np(doctest_namespace):
doctest_namespace["np"] = numpy
doctest_namespace["nb"] = nibabel
doctest_namespace["os"] = os
doctest_namespace["Path"] = Path
doctest_namespace["layouts"] = layouts
for key, val in list(layouts.items()):
doctest_namespace[key] = Path(val.root)

doctest_namespace["dsA_dir"] = data_dir / "dsA"
doctest_namespace["dsB_dir"] = data_dir / "dsB"
doctest_namespace["dsC_dir"] = data_dir / "dsC"
def doctest_fixture(doctest_namespace, request):
doctest_plugin = request.config.pluginmanager.getplugin("doctest")
if isinstance(request.node, doctest_plugin.DoctestItem):
doctest_namespace.update(
np=numpy,
nb=nibabel,
os=os,
Path=Path,
layouts=layouts,
dsA_dir=data_dir / "dsA",
dsB_dir=data_dir / "dsB",
dsC_dir=data_dir / "dsC",
)
doctest_namespace.update((key, Path(val.root)) for key, val in layouts.items())

# Start every doctest clean, and clean up after ourselves
clear_registry()
yield
clear_registry()
else:
yield


@pytest.fixture
Expand Down

0 comments on commit 2ecccba

Please sign in to comment.