From: Andreas Schneider Date: Tue, 24 Jan 2023 08:18:46 +0000 (+0100) Subject: python:tests: Avoid exceptions in cleanup code if a test fails in smb3unix.py X-Git-Tag: tevent-0.14.1~58 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e6f0e4d53285177f7a60559394efeb5a78b6bd53;p=thirdparty%2Fsamba.git python:tests: Avoid exceptions in cleanup code if a test fails in smb3unix.py Signed-off-by: Andreas Schneider Reviewed-by: Ralph Boehme --- diff --git a/python/samba/tests/smb3unix.py b/python/samba/tests/smb3unix.py index 3ad49af09fa..d8f9b7d5c33 100644 --- a/python/samba/tests/smb3unix.py +++ b/python/samba/tests/smb3unix.py @@ -189,8 +189,9 @@ class Smb3UnixTests(samba.tests.libsmb.LibsmbTests): 'SMB2_FIND_POSIX_INFORMATION failed to list contents') finally: - for fname in test_files: - self.delete_test_file(c, fname) + if len(test_files) > 0: + for fname in test_files: + self.delete_test_file(c, fname) self.disable_smb3unix() @@ -283,6 +284,7 @@ class Smb3UnixTests(samba.tests.libsmb.LibsmbTests): self.disable_smb3unix() def test_posix_perm_files(self): + test_files = {} try: self.enable_smb3unix() @@ -294,7 +296,6 @@ class Smb3UnixTests(samba.tests.libsmb.LibsmbTests): posix=True) self.assertTrue(c.have_posix()) - test_files = {} for perm in range(0o600, 0o7777+1): # Owner write permission is required or cleanup will fail, and # owner read is required to list the file if O_PATH is disabled @@ -332,8 +333,9 @@ class Smb3UnixTests(samba.tests.libsmb.LibsmbTests): (test_files[fname], found_files[fname])) finally: - for fname in test_files.keys(): - self.delete_test_file(c, '\\%s' % fname) + if len(test_files) > 0: + for fname in test_files.keys(): + self.delete_test_file(c, '\\%s' % fname) self.disable_smb3unix()