File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff 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
1735def mock_now ():
1836 return datetime .now (tz = timezone .utc )
You can’t perform that action at this time.
0 commit comments