Skip to content

Commit

Permalink
Ignore FileNotFoundError on GPG tests teardown
Browse files Browse the repository at this point in the history
There is a suspected race condition when calling shutil.rmtree so we are
ignoring any FileNotFoundError when the test class calls tearDownClass
Fixes #397

Signed-off-by: Andrés Torres <[email protected]>
  • Loading branch information
elfotografo007 committed Apr 11, 2022
1 parent 692b14d commit 7d6fe23
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions tests/test_gpg.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@
ANY_PUBKEY_DICT_SCHEMA)


class GPGTestUtils:
"""GPG Test utility class"""

@staticmethod
def ignore_not_found_error(function, path, exc_info):
"""Callback that ignores FileNotFoundError"""
_, error, _ = exc_info
if not isinstance(error, FileNotFoundError):
raise error


@unittest.skipIf(not HAVE_GPG, "gpg not found")
class TestUtil(unittest.TestCase):
"""Test util functions. """
Expand Down Expand Up @@ -503,7 +514,7 @@ def setUpClass(self):
def tearDownClass(self):
"""Change back to initial working dir and remove temp test directory. """
os.chdir(self.working_dir)
shutil.rmtree(self.test_dir)
shutil.rmtree(self.test_dir, onerror=GPGTestUtils.ignore_not_found_error)

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

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

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

0 comments on commit 7d6fe23

Please sign in to comment.