Skip to content

Commit

Permalink
TEST: Chdir during doctest to avoid polluting the working dir
Browse files Browse the repository at this point in the history
  • Loading branch information
effigies committed Dec 6, 2023
1 parent 60c3afb commit 07289b7
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions nibabel/externals/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import pytest

try:
from contextlib import chdir as _chdir
except ImportError: # PY310
import os
from contextlib import contextmanager

@contextmanager # type: ignore
def _chdir(path):
cwd = os.getcwd()
os.chdir(path)
try:
yield
finally:
os.chdir(cwd)


@pytest.fixture(autouse=True)
def chdir_tmpdir(request, tmp_path):
if request.node.__class__.__name__ == "DoctestItem":
with _chdir(tmp_path):
yield
else:
yield

0 comments on commit 07289b7

Please sign in to comment.