MCPcopy Create free account
hub / github.com/dmlc/treelite / TemporaryDirectory

Function TemporaryDirectory

tests/python/util.py:124–140  ·  view source on GitHub ↗

Simulate the effect of 'ignore_cleanup_errors' parameter of tempfile.TemporaryDirectory. The parameter is only available for Python >= 3.10.

(*args, **kwargs)

Source from the content-addressed store, hash-verified

122
123@contextmanager
124def TemporaryDirectory(*args, **kwargs):
125 # pylint: disable=C0103
126 """
127 Simulate the effect of 'ignore_cleanup_errors' parameter of tempfile.TemporaryDirectory.
128 The parameter is only available for Python >= 3.10.
129 """
130 if "PYTEST_TMPDIR" in os.environ and "dir" not in kwargs:
131 kwargs["dir"] = os.environ["PYTEST_TMPDIR"]
132 tmpdir = tempfile.TemporaryDirectory(*args, **kwargs)
133 try:
134 yield tmpdir.name
135 finally:
136 try:
137 tmpdir.cleanup()
138 except (PermissionError, NotADirectoryError):
139 if _platform != "win32":
140 raise

Calls

no outgoing calls