Simulate the effect of 'ignore_cleanup_errors' parameter of tempfile.TemporaryDirectory. The parameter is only available for Python >= 3.10.
(*args, **kwargs)
| 122 | |
| 123 | @contextmanager |
| 124 | def 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 |
no outgoing calls