-def tmpdir(tmp_path):
- try:
- yield bytes(tmp_path)
- finally:
- subprocess.call([b'chmod', b'-R', b'u+rwX', bytes(tmp_path)])
- # FIXME: delete only if there are no errors
- #subprocess.call(['rm', '-rf', tmpdir])
+def tmpdir(request):
+ if sys.version_info[0] > 2:
+ rp = realpath(fsencode(request.fspath))
+ else:
+ rp = realpath(str(request.fspath))
+ rp = relpath(rp, _bup_test_dir)
+ if request.function:
+ rp += b'-' + fsencode(request.function.__name__)
+ safe = _safe_path_rx.sub(b'-', rp)
+ tmpdir = tempfile.mkdtemp(dir=_bup_tmp, prefix=safe)
+ yield tmpdir
+ if request.node.bup['call-report'].failed:
+ print('\nPreserving:', b'test/' + relpath(tmpdir, _bup_test_dir),
+ file=sys.stderr)
+ else:
+ subprocess.call(['chmod', '-R', 'u+rwX', tmpdir])
+ subprocess.call(['rm', '-rf', tmpdir])