diff options
| -rw-r--r-- | lang/python/tests/support.py | 21 | 
1 files changed, 10 insertions, 11 deletions
| diff --git a/lang/python/tests/support.py b/lang/python/tests/support.py index a381270d..69aa7a40 100644 --- a/lang/python/tests/support.py +++ b/lang/python/tests/support.py @@ -78,17 +78,16 @@ def mark_key_trusted(ctx, key):          ctx.op_edit(key, Editor().edit, sink, sink) -# Python2/3 compatibility -if hasattr(tempfile, "TemporaryDirectory"): -    # Python3.2 and up -    TemporaryDirectory = tempfile.TemporaryDirectory -else: -    class TemporaryDirectory(object): -        def __enter__(self): -            self.path = tempfile.mkdtemp() -            return self.path -        def __exit__(self, *args): -            shutil.rmtree(self.path) +# Python3.2 and up has tempfile.TemporaryDirectory, but we cannot use +# that, because there shutil.rmtree is used without +# ignore_errors=True, and that races against gpg-agent deleting its +# sockets. +class TemporaryDirectory(object): +    def __enter__(self): +        self.path = tempfile.mkdtemp() +        return self.path +    def __exit__(self, *args): +        shutil.rmtree(self.path, ignore_errors=True)  @contextlib.contextmanager  def EphemeralContext(): | 
