Skip to content

Commit d98b32c

Browse files
author
Lukas Pühringer
authored
Merge pull request #400 from elfotografo007/397-fix-gpg-test-cleanup-race-condition
Ignore FileNotFoundError on GPG tests teardown
2 parents 2af04d1 + 7d6fe23 commit d98b32c

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

tests/test_gpg.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,17 @@
5959
ANY_PUBKEY_DICT_SCHEMA)
6060

6161

62+
class GPGTestUtils:
63+
"""GPG Test utility class"""
64+
65+
@staticmethod
66+
def ignore_not_found_error(function, path, exc_info):
67+
"""Callback that ignores FileNotFoundError"""
68+
_, error, _ = exc_info
69+
if not isinstance(error, FileNotFoundError):
70+
raise error
71+
72+
6273
@unittest.skipIf(not HAVE_GPG, "gpg not found")
6374
class TestUtil(unittest.TestCase):
6475
"""Test util functions. """
@@ -503,7 +514,7 @@ def setUpClass(self):
503514
def tearDownClass(self):
504515
"""Change back to initial working dir and remove temp test directory. """
505516
os.chdir(self.working_dir)
506-
shutil.rmtree(self.test_dir)
517+
shutil.rmtree(self.test_dir, onerror=GPGTestUtils.ignore_not_found_error)
507518

508519
def test_export_pubkey_error(self):
509520
"""Test correct error is raised if function called incorrectly. """
@@ -664,7 +675,7 @@ def setUpClass(self):
664675
def tearDownClass(self):
665676
"""Change back to initial working dir and remove temp test directory. """
666677
os.chdir(self.working_dir)
667-
shutil.rmtree(self.test_dir)
678+
shutil.rmtree(self.test_dir, onerror=GPGTestUtils.ignore_not_found_error)
668679

669680
def test_export_pubkey(self):
670681
""" export a public key and make sure the parameters are the right ones:
@@ -749,7 +760,7 @@ def setUpClass(self):
749760
def tearDownClass(self):
750761
"""Change back to initial working dir and remove temp test directory. """
751762
os.chdir(self.working_dir)
752-
shutil.rmtree(self.test_dir)
763+
shutil.rmtree(self.test_dir, onerror=GPGTestUtils.ignore_not_found_error)
753764

754765
def test_gpg_sign_and_verify_object_with_default_key(self):
755766
"""Create a signature using the default key on the keyring """

0 commit comments

Comments
 (0)