Implement retention policy none

This commit is contained in:
Yusuke Kadowaki 2022-10-23 21:53:46 +09:00
parent e9ee831d9f
commit 1a358eec2f
2 changed files with 8 additions and 3 deletions

View File

@ -357,8 +357,10 @@ def make_numbered_dir_with_cleanup(
for i in range(10): for i in range(10):
try: try:
p = make_numbered_dir(root, prefix, mode) p = make_numbered_dir(root, prefix, mode)
lock_path = create_cleanup_lock(p) # Do not lock the current dir when keep is 0
register_cleanup_lock_removal(lock_path) if keep != 0:
lock_path = create_cleanup_lock(p)
register_cleanup_lock_removal(lock_path)
except Exception as exc: except Exception as exc:
e = exc e = exc
else: else:

View File

@ -154,10 +154,13 @@ class TempPathFactory:
) )
if (rootdir_stat.st_mode & 0o077) != 0: if (rootdir_stat.st_mode & 0o077) != 0:
os.chmod(rootdir, rootdir_stat.st_mode & ~0o077) os.chmod(rootdir, rootdir_stat.st_mode & ~0o077)
keep = self._retention_count
if self._retention_policy == "none":
keep = 0
basetemp = make_numbered_dir_with_cleanup( basetemp = make_numbered_dir_with_cleanup(
prefix="pytest-", prefix="pytest-",
root=rootdir, root=rootdir,
keep=self._retention_count, keep=keep,
lock_timeout=LOCK_TIMEOUT, lock_timeout=LOCK_TIMEOUT,
mode=0o700, mode=0o700,
) )