python: Make tests more robust.
* lang/python/tests/support.py (TemporaryDirectory): Always use our own version even if 'tempfile.TemporaryDirectory' is provided, because we need to use 'shutil.rmtree(..., ignore_errors=True)' to avoid it tripping over gpg-agent deleting its own sockets. Signed-off-by: Justus Winter <justus@g10code.com>
This commit is contained in:
parent
a4201035fd
commit
ac48499538
@ -78,17 +78,16 @@ def mark_key_trusted(ctx, key):
|
|||||||
ctx.op_edit(key, Editor().edit, sink, sink)
|
ctx.op_edit(key, Editor().edit, sink, sink)
|
||||||
|
|
||||||
|
|
||||||
# Python2/3 compatibility
|
# Python3.2 and up has tempfile.TemporaryDirectory, but we cannot use
|
||||||
if hasattr(tempfile, "TemporaryDirectory"):
|
# that, because there shutil.rmtree is used without
|
||||||
# Python3.2 and up
|
# ignore_errors=True, and that races against gpg-agent deleting its
|
||||||
TemporaryDirectory = tempfile.TemporaryDirectory
|
# sockets.
|
||||||
else:
|
class TemporaryDirectory(object):
|
||||||
class TemporaryDirectory(object):
|
def __enter__(self):
|
||||||
def __enter__(self):
|
self.path = tempfile.mkdtemp()
|
||||||
self.path = tempfile.mkdtemp()
|
return self.path
|
||||||
return self.path
|
def __exit__(self, *args):
|
||||||
def __exit__(self, *args):
|
shutil.rmtree(self.path, ignore_errors=True)
|
||||||
shutil.rmtree(self.path)
|
|
||||||
|
|
||||||
@contextlib.contextmanager
|
@contextlib.contextmanager
|
||||||
def EphemeralContext():
|
def EphemeralContext():
|
||||||
|
Loading…
Reference in New Issue
Block a user