Skip to content

Commit 6ef726a

Browse files
authored
bpo-29734: Cleanup test_getfinalpathname_handles test (GH-12908)
1 parent d59b662 commit 6ef726a

File tree

1 file changed

+14
-21
lines changed

1 file changed

+14
-21
lines changed

Lib/test/test_os.py

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2337,19 +2337,10 @@ def test_unlink_removes_junction(self):
23372337

23382338
@unittest.skipUnless(sys.platform == "win32", "Win32 specific tests")
23392339
class Win32NtTests(unittest.TestCase):
2340-
def setUp(self):
2341-
from test import support
2342-
self.nt = support.import_module('nt')
2343-
pass
2344-
2345-
def tearDown(self):
2346-
pass
2347-
23482340
def test_getfinalpathname_handles(self):
2349-
try:
2350-
import ctypes, ctypes.wintypes
2351-
except ImportError:
2352-
raise unittest.SkipTest('ctypes module is required for this test')
2341+
nt = support.import_module('nt')
2342+
ctypes = support.import_module('ctypes')
2343+
import ctypes.wintypes
23532344

23542345
kernel = ctypes.WinDLL('Kernel32.dll', use_last_error=True)
23552346
kernel.GetCurrentProcess.restype = ctypes.wintypes.HANDLE
@@ -2368,21 +2359,23 @@ def test_getfinalpathname_handles(self):
23682359
before_count = handle_count.value
23692360

23702361
# The first two test the error path, __file__ tests the success path
2371-
filenames = [ r'\\?\C:',
2372-
r'\\?\NUL',
2373-
r'\\?\CONIN',
2374-
__file__ ]
2362+
filenames = [
2363+
r'\\?\C:',
2364+
r'\\?\NUL',
2365+
r'\\?\CONIN',
2366+
__file__,
2367+
]
23752368

2376-
for i in range(10):
2369+
for _ in range(10):
23772370
for name in filenames:
23782371
try:
2379-
tmp = self.nt._getfinalpathname(name)
2380-
except:
2372+
nt._getfinalpathname(name)
2373+
except Exception:
23812374
# Failure is expected
23822375
pass
23832376
try:
2384-
tmp = os.stat(name)
2385-
except:
2377+
os.stat(name)
2378+
except Exception:
23862379
pass
23872380

23882381
ok = kernel.GetProcessHandleCount(hproc, ctypes.byref(handle_count))

0 commit comments

Comments
 (0)