Skip to content

Commit 7652cc1

Browse files
committed
Add monkeypatch_tmpdir fixture
1 parent c1b4ee0 commit 7652cc1

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

skore/tests/conftest.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,24 @@ def pytest_configure(config):
1313
matplotlib.use("agg")
1414

1515

16+
@pytest.fixture(autouse=True)
17+
def monkeypatch_tmpdir(monkeypatch, tmp_path):
18+
"""
19+
Change ``TMPDIR`` used by ``tempfile.gettempdir()`` to point to ``tmp_path``, so
20+
that it is automatically deleted after use, with no impact on user's environment.
21+
22+
Force the reload of the ``tempfile`` module to change the cached return of
23+
``tempfile.gettempdir()``.
24+
25+
https://docs.python.org/3/library/tempfile.html#tempfile.gettempdir
26+
"""
27+
import importlib
28+
import tempfile
29+
30+
monkeypatch.setenv("TMPDIR", str(tmp_path))
31+
importlib.reload(tempfile)
32+
33+
1634
@pytest.fixture
1735
def mock_now():
1836
return datetime.now(tz=timezone.utc)

0 commit comments

Comments
 (0)