From 4b11bc8b8df2895989435a4c9af109736fbe75be Mon Sep 17 00:00:00 2001 From: junkmd Date: Sat, 7 Dec 2024 07:54:29 +0900 Subject: [PATCH] Update `setUpModule` and add `tearDownModule`. --- comtypes/test/test_dispinterface.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/comtypes/test/test_dispinterface.py b/comtypes/test/test_dispinterface.py index 734020b5..5ef029eb 100644 --- a/comtypes/test/test_dispinterface.py +++ b/comtypes/test/test_dispinterface.py @@ -2,17 +2,23 @@ import unittest import comtypes.test.TestDispServer -from comtypes.server.register import register # , unregister +from comtypes.server.register import register, unregister def setUpModule(): - raise unittest.SkipTest( - "This test requires the tests to be run as admin since it tries to " - "register the test COM server. Is this a good idea?" - ) + try: + register(comtypes.test.TestDispServer.TestDispServer) + except WindowsError as e: + if e.winerror != 5: # [Error 5] Access is denied + raise e + raise unittest.SkipTest( + "This test requires the tests to be run as admin since it tries to " + "register the test COM server." + ) + - # If this test is ever NOT skipped, then this line needs to run. Keeping it here for posterity. - register(comtypes.test.TestDispServer.TestDispServer) +def tearDownModule(): + unregister(comtypes.test.TestDispServer.TestDispServer) @unittest.skip("This depends on 'pywin32'.")