Skip to content

Commit 07289b7

Browse files
committed
TEST: Chdir during doctest to avoid polluting the working dir
1 parent 60c3afb commit 07289b7

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

nibabel/externals/conftest.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import pytest
2+
3+
try:
4+
from contextlib import chdir as _chdir
5+
except ImportError: # PY310
6+
import os
7+
from contextlib import contextmanager
8+
9+
@contextmanager # type: ignore
10+
def _chdir(path):
11+
cwd = os.getcwd()
12+
os.chdir(path)
13+
try:
14+
yield
15+
finally:
16+
os.chdir(cwd)
17+
18+
19+
@pytest.fixture(autouse=True)
20+
def chdir_tmpdir(request, tmp_path):
21+
if request.node.__class__.__name__ == "DoctestItem":
22+
with _chdir(tmp_path):
23+
yield
24+
else:
25+
yield

0 commit comments

Comments
 (0)