Return an absolute pathname of a file or dir that did not exist at the time this call is made. Also schedule it for safe deletion at interpreter exit. It's technically racy but probably not really due to the time variant.
(suffix="", dir=None)
| 126 | |
| 127 | |
| 128 | def get_testfn(suffix="", dir=None): |
| 129 | """Return an absolute pathname of a file or dir that did not |
| 130 | exist at the time this call is made. Also schedule it for safe |
| 131 | deletion at interpreter exit. It's technically racy but probably |
| 132 | not really due to the time variant. |
| 133 | """ |
| 134 | if dir is None: |
| 135 | dir = os.getcwd() |
| 136 | while True: |
| 137 | name = tempfile.mktemp(prefix=TESTFN_PREFIX, suffix=suffix, dir=dir) |
| 138 | if not os.path.exists(name): # also include dirs |
| 139 | return os.path.basename(name) |
| 140 | |
| 141 | |
| 142 | def safe_rmpath(path): |